0

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?

3
  • Is that the code you actually use? Because then the cause is that you use: $xPath->query('//words/word') instead of $xPath_Hitzak->query('//words/word') Commented Apr 21, 2012 at 11:52
  • Ok Thanks, my fault, I didnt realised about that, it's working fine now. Thamks @Mircea Commented Apr 21, 2012 at 11:55
  • @Mircea: Please add your solution as an answer below so that Haritz can accept it later. Commented May 2, 2012 at 9:35

1 Answer 1

1

You should use: $xPath->query('//words/word') instead of $xPath_Hitzak->query('//words/word')

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.