私はここにクレイジーに行くよ...再び!xpathなしでsimplexmlobjectから文字列を取得
私はこのsimplexmlのファイルがあります... 2010-07-08 次のコードは動作します:私は、この特定の方法で "DateCreated" を持ちたい
SimpleXMLElement Object
(
[PubmedArticle] => Array
(
[0] => SimpleXMLElement Object
(
[MedlineCitation] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Owner] => NLM
[Status] => In-Process
)
[PMID] => 20538400
[DateCreated] => SimpleXMLElement Object
(
[Year] => 2010
[Month] => 07
[Day] => 08
)
[Article] => SimpleXMLElement Object
(
[@attributes] => Array
(
[PubModel] => Print-Electronic
)
etc.....
を
foreach ($xml->xpath('//MedlineCitation') as $MedlineCitation)
{
foreach ($MedlineCitation->DateCreated as $date)
{
foreach ($date as $ymd)
{
$datecreated .= $ymd . "-";
}
$datecreated = substr($datecreated, 0, -1);
echo $datecreated;
$datecreated = "";
}
}
出力:2010-07-08 しかし...私は、XPathでは動作しません。この「foreachループ」のコードの別の平和を持っている必要がありますので、私は、XPathのなしでそれをしたい...
このコードは動作しませんしません....:
foreach ($xml->PubmedArticle as $MedlineCitation)
{
foreach ($MedlineCitation->DateCreated as $date)
{
foreach ($date as $ymd)
{
$datecreated .= $ymd . "-";
}
$datecreated = substr($datecreated, 0, -1);
echo $datecreated;
$datecreated = "";
}
}
そして、これもない鍋を行い...:
foreach ($xml->PubmedArticle as $MedlineCitation)
{
$datecreated = "";
$datecreated = $MedlineCitation->DateCreated->Year;
$datecreated = $datecreated . "-" . $MedlineCitation->DateCreated->Month;
$datecreated = $datecreated . "-" . $MedlineCitation->DateCreated->Day;
echo $datecreated;
}
よろしく! タイス
よろしくお願いいたします。これが解決策です!私は構造の1つのレベルを逃した! – Thijs