PHP4 XML Parser when $data is empty..
Thursday, 21st January 2010
by DamianHart
I've been using the tutorial about setting up an XML parser using PHP4 (because that's as advanced as this company has at the moment). It's worked well for several projects. However, I've recently run into a bump that I hope you can help with. Specifically, I'm dealing with the part on page 7 (http://www.developertutorials.com/tutorials/php/parsing-xml-using-php4-050816/page7.html) where, after getting into an XML node, we then look at the data in that node.
So, if I have something in my xml file like: <Note>This is my comment</Note> it would pull out "This is my comment" and let me work with it.
However, my current situation is if the Note node is empty, the xml looks like this: <Note />
Now, in the PHP parser I use a global $NodeName to keep track of what Node I'm in, so in the start_tag area, I make $NodeName = $name...
In the area where I pull out my data, then, I have things like this:
if($NodeName == "FirstName")
{
$FirstName = $data;
}
else if($NodeName == "LastName")
{
$LastName = $data;
}
else if($NodeName == "Note")
{
$Note = $data;
}
..and so on.
What seems to be happening is if the node is empty <Note /> then the parser skips over the data-extraction section entirely (or so it seems). I've put in tests to see if($data == "" || $data == NULL) ...but get no reply. It really seems as if the node is empty, then $data is empty, and it doesn't go into the extraction part.
Thing is: I need it to, even if there is not a note.
So....how can I catch this situation?
Thanks for your help.
---Damian
|