Re: Re: Getting data from XML
| From: | Eamon Reyn | Date: | Tue, 03 Aug 2004 14:50:21 +0000 |
| Subject: | Re: Re: Getting data from XML | ||
| References: | 1 2 3 | Groups: | php.xml.dev |
| Request: | Send a blank email to php-xml-dev+get-442@lists.php.net to get a copy of this message | ||
"Adam Maccabee Trachtenberg" <adam@trachtenberg.com> wrote in message
news:Pine.LNX.4.58.0407281522250.26510@miranda.org...
> 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
>
> --
> adam@trachtenberg.com
> 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