0

PHPを使用してxml属性にアクセスしようとしています。どのフィールドの実際のテキストにもアクセスできますが、

たとえば、xml ファイルの行は次のようになります。

<Competitor CODE1="MIN" CODE3="MIN" CODE4="l.mlb.com-t.10" ID="69" LineOrderOverride="" NAME="Minnesota Twins" NUM="1" ROT="927" SCORE="5">Game 1</Competitor>

私が使用しているコードは「ゲーム 1」を表示しますが、NAME と SCORE の値にアクセスできるようにしたいです

@$doc->load($feedURL);
$arrFeeds = array();
foreach ($doc->getElementsByTagName('Event') as $node) {
$itemRSS = array ( 
echo strip_tags(str_replace("'","",$node->getElementsByTagName('Competitor')->item(0)->nodeValue));
};

PHP を使用してメタ変数にアクセスする方法を知っている人はいますか?

4

1 に答える 1

0

foreach() 内に追加します

echo $node->getElementsByTagName('Competitor')->item(0)->getAttribute("NAME"); // For NAME
echo $node->getElementsByTagName('Competitor')->item(0)->getAttribute("SCORE"); // For SCORE
于 2013-09-23T00:09:24.310 に答える