Reputation: 1752
I am developing an application were I need to transform XML documents that look like this(words.xml):
<?xml version='1.0' encoding='ISO-8859-1'?>
<!DOCTYPE words SYSTEM "words.dtd">
<words>
<word id="word_1">Alfa</word>
<word id="word_2">Beta</word>
<word id="word_3">Gamma</word>
<word id="word_4">Delta</word>
<word id="word_5">Zeta</word>
</words>
Using PHP5 and DOM. I would like the result to be (in this case):
word_1 = Alfa
My PHP code is this:
<?php
$xmlHitzakDok = new DOMDocument();
if($xmlHitzakDok->load("words.xml") === FALSE){die('Errorea hitzen xml-a kargatzean');}
$xPath_Hitzak = new DOMXPath($xmlHitzakDok);
$Hurrengo_Hitza = 'word_1';
foreach ($xPath->query('//words/word') AS $item)
{
if ($item->getAttribute('id') == $Hurrengo_Hitza)
{
echo $item->getAttribute('id') . " = " . $item->nodeValue . "<br />";
}
}
I am getting no results. Which is the problem?
Upvotes: 0
Views: 95
Reputation: 925
You should use: $xPath->query('//words/word') instead of $xPath_Hitzak->query('//words/word')
Upvotes: 1