Re: [PHP-XML-DEV] Re: Getting data from XML

[email protected] ("Eamon Reyn") Wed, 4 Aug 2004 02:50:21 +1200
Newsgroups php.xml.dev
Message-ID <[email protected]>
"Adam Maccabee Trachtenberg" <[email protected]> wrote in message
news:[email protected]...
> On Wed, 28 Jul 2004, Eamon Reyn wrote:
>
> > this will print everything out but will do an extra lot at the beginning
for
> > the root node e.g.
> >
> > root = Hello Bye
> > Tag1 = Hello
> > Tag2 = Bye
>
> You should check the element's node type. (i.e. nodeType ==
> XML_ELEMENT_NODE or XML_TEXT_NODE)
>
> -adam
>
> -- 
> [email protected]
> author of o'reilly's "upgrading to php 5" and "php cookbook"
> avoid the holiday rush, buy your copies today!


Hi Adam I tried using the following code (as suggested) if(nodeType ==
XML_TEXT_NODE) I assume this should allow me to pull out the nodes which
just have text (e.g. the Hello and Bye nodes from the example above and not
the root node which contains all the other nodes) but it just printed a
blank page if I use the XML_ELEMENT_NODE option I get the same problem as
listed above (it prints out everything) here is the sample of code I use
(this prints a blank page):

    $xmlDOM = new DOMDocument();
    $xmlDOM->load('test.xml');

    $domData = $xmlDOM->getElementsByTagName("*");
    foreach ($domData as $discreetData){

        if ($discreetData->nodeType == XML_TEXT_NODE){
            print $discreetData->nodeName . " = " . $discreetData->nodeValue
. "<br><br>";
        }
    }

here is the contents of the very simple xml file as it appears:

<?xml version="1.0"?>
<root>
    <tag1>Hello</tag1>
    <tag2>Bye</tag2>
</root>

Any ideas would be really useful.
Eamon