Connecting Tech Pros Worldwide Help | Site Map

problem when outputting an xml file using php

mr_burns
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi there,

I am trying to output a file, coutries.xml, which is in the following
format:

<xml...
<countries>
<country id="1">Afghanistan</country>
<country id="2">Albania</country>
Janwillem Borleffs
Guest
 
Posts: n/a
#2: Jul 17 '05

re: problem when outputting an xml file using php


mr_burns wrote:[color=blue]
> It is managing to output the 'id' attribute but the node value isnt
> appearing. Can anybody tell me how to sort it? Cheers
>[/color]

Switched over to PHP 5 already? Then try the following:

<?php

$xml_document = new DomDocument;
$xml_document->load('xml/countries.xml');

if ($xml_document) {
$items = $xml_document->getElementsByTagName('country');
for ($i = 0; $i < $items->length; $i++) {
$item = $items->item($i);
print $item->getAttribute('id') . " = " . $item->nodeValue . "<br>";
}
}

?>


JW



mr_burns
Guest
 
Posts: n/a
#3: Jul 17 '05

re: problem when outputting an xml file using php


Hi,

I tried your code but got the following error:

Warning: domdocument() expects at least 1 parameter, 0 given in
/home/martyn69/public_html/oarsome/test_countries.php on line 35

Fatal error: Call to undefined function: load() in
/home/martyn69/public_html/oarsome/test_countries.php on line 36



It seems that the code I am using is opening the XML file, getting
into the FOR loop and is managing to spit out the 'id' attribute. The
only problem is the $item->node_value() isnt producing the node value.

Any ideas? Why isnt node_value() producing the node value? Am I
missing something? Cheers

Burnsy
mr_burns
Guest
 
Posts: n/a
#4: Jul 17 '05

re: problem when outputting an xml file using php


Ive just posted a reply saying that I was still having trouble (this
one might beat it to it though).

I have managed to sort node_value(), Ive used get_content() instead
and its working now. Cheers
Closed Thread