Re: Getting data from XML
[email protected] ("Eamon Reyn") Wed, 28 Jul 2004 22:13:42 +1200
| Newsgroups | php.xml.dev |
|---|---|
| Message-ID | <[email protected]> |
From: "Eamon Reyn" <[email protected]> Newsgroups: php.xml.dev To: <[email protected]> Sent: Monday, July 19, 2004 12:33 AM Subject: Getting data from XML > Hey People, > > I was wondering if anyone could point me to an example or give me an example > of data extraction from an XML document where you do not necessarily know > the contents of the XML document. > > I am using PHP 5 RC3 and can see a lot of references to methods like > getelementbytagname or getbyid etc but what if the data I am getting is not > what I expected however I still want to display it. > Hmm I am still having problems with this and realise I did not explain it all that well so am going to give it another bash. I want to navigate an xml document and print out the values of the tags and the tag name where I do not necessarilly know the content of the xml file so a quick example of the sort of thing I want to do follows: xml contains the following <root> <tag1> Hello </tag1> <tag2> Bye </tag2> </root> the following displays in a table Tag1 Tag2 Hello Bye Obviuosly this could be a lot more complex but the example is not complete rubbish for now. the following is the code I am trying to work with at the moment (all I am trying to do is get all the data printing at this point no table rubbish): $domData = $this->Dom->getElementsByTagName("*"); foreach ($domData as $discreetData){ print $discreetData->nodeName . " = " . $discreetData->nodeValue . "<br><br>"; } 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 I tried the following but then nothing prints out: if (!$discreetData->hasChildNodes()) Any help would be appreciated. Thanks, Eamon.