problem when outputting an xml file using php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mr_burns

    problem when outputting an xml file using php

    Hi there,

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

    <xml...
    <countries>
    <country id="1">Afghanis tan</country>
    <country id="2">Albania </country>
  • Janwillem Borleffs

    #2
    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->getElementsByT agName('country ');
    for ($i = 0; $i < $items->length; $i++) {
    $item = $items->item($i);
    print $item->getAttribute(' id') . " = " . $item->nodeValue . "<br>";
    }
    }

    ?>


    JW



    Comment

    • mr_burns

      #3
      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

      Comment

      • mr_burns

        #4
        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

        Comment

        Working...