I think that simpleXML is the best thing i've seen in PHP5. It's so
simple (d'ho!) and easy to use when
it comes to reading a simple XML file. The only thing i'm not sure how
to achieve is finding if an XML
node is empty or if the node exist or doesn't exist.
I'm searching the web, but got nothing yet. I was thinking of posting
it here.
This is a condensed version of the code:
<?xml version="1.0" encoding="UTF-8"?>
<CD>
<title>Shine</title>
<year>1985</year>
<label></label>
<description>Good CD from the 1980s</description>
<item>
<track id="18">Moonlight</track>
<track>Shine</track>
<track>Absolute</track>
</item>
<item>
<track>Relative</track>
<track>Star</track>
<track>Crazy</track>
</item>
</CD>
$file = 'db_cd_number.xml';
$xml = @simplexml_load_file($file);
//??????
if(title node is empty || title node doesn't exist) {
echo 'title is empty or doesnt exist, do something';
} else {
echo 'title OK, continue';
}
//i.e. 2 What about attributes??????????
foreach ($xml->item-as $item) {
foreach($item->track as $track) {
if($track['id'] doesn't exist or empty) {
echo 'dont show the lyrics';
}
}
}
How do i find if a node is empty or if it exists?
Thanks
Marco