Helping ordinary people create extraordinary websites!
   

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






More PHP Help:
» How can I display different content for different users with PHP?
» What is PHP?
» How can I make a PHP page reload continually forever?
» How to setup user level menu access management?
» Fatal error: Call to undefined function domxml_open_mem() in...?
» How to convert my HTML website to PHP?
» How to add RSS feeds into my web page with PHP?
» How to count all listings in a Category in PHP?


Leave a Comment on "PHP4 XML Parser when $data is empty.."
You must be logged in to post a comment.

Link to This Question!


GET OUR NEWSLETTERS