View Full Version : Value of 0 not displaying on page
wprjr
06-21-2007, 05:20 AM
I haven't touched XML in over four years, so please forgive me for asking a stupid question. I am using PHP to parse the values from the XML file.
I'm generating an XML file and some tags will contain a legitimate value of 0 (zero). Example <tagname>0</tagname>
If the value is greater than 0, say <tagname>1</tagname>, the value will be displayed on the page, but a value of 0 simply generates a blank space. Is there some CDATA I need to add to the tag sets to make a value of 0 acceptable to my parsing code?
Thanks.
_Aerospace_Eng_
06-21-2007, 05:22 AM
Try
<tagname><![CDATA[0]]></tagname>
though if its just 0 you could put an attribute in tagname and set its value to the correct number
<tagname num="0" />
wprjr
06-21-2007, 05:44 AM
Hmmm. OK. The CDATA didn't work..
Here is a sample of the setup of the xml file:
<?xml version="1.0"?>
<leaguetable>
<position>
<club>Aberdeen</club>
<played>0</played>
<wins>0</wins>
<draws><![CDATA[0]]></draws>
<losses>0</losses>
<goalsfor>0</goalsfor>
<goalsagainst>0</goalsagainst>
<goaldiff>0</goaldiff>
<points>0</points>
</position>
</leaguetable>
I'm using the class here (http://www.troywolf.com/articles/php/class_xml/) to parse my code. And the actual PHP code that is used to display the contents of the tags...
foreach ($x->data->LEAGUETABLE[0]->POSITION[$i]->CLUB as $club) {
echo " \n<tr>\n <td>".$club->_text."</td>\n";
foreach ($x->data->LEAGUETABLE[0]->POSITION[$i]->PLAYED as $p) {
echo " <td>".$p->_text."</td>\n";
}
foreach ($x->data->LEAGUETABLE[0]->POSITION[$i]->WINS as $w) {
echo " <td>".$w->_text."</td>\n";
}
foreach ($x->data->LEAGUETABLE[0]->POSITION[$i]->DRAWS as $d) {
echo " <td>".$d->_text."</td>\n";
}
foreach ($x->data->LEAGUETABLE[0]->POSITION[$i]->LOSSES as $l) {
echo " <td>".$l->_text."</td>\n";
}
foreach ($x->data->LEAGUETABLE[0]->POSITION[$i]->GOALSFOR as $gf) {
echo " <td>".$gf->_text."</td>\n";
}
foreach ($x->data->LEAGUETABLE[0]->POSITION[$i]->GOALSAGAINST as $ga) {
echo " <td>".$ga->_text."</td>\n";
}
foreach ($x->data->LEAGUETABLE[0]->POSITION[$i]->GOALDIFF as $gd) {
echo " <td>".$gd->_text."</td>\n";
}
foreach ($x->data->LEAGUETABLE[0]->POSITION[$i]->POINTS as $pts) {
echo " <td>".$pts->_text."</td>\n";
}
}
_Aerospace_Eng_
06-21-2007, 08:16 AM
Hmm changing the xml to have 1's instead of 0's it works fine. I still think you should use an xml file that looks like this
<?xml version="1.0" encoding="utf-8"?>
<leaguetable>
<position>
<club value="Aberdeen" />
<played value="0" />
<wins value="0" />
<draws value="0" />
<losses value="0" />
<goalsfor value="0" />
<goalsagainst value="0" />
<goaldiff value="0" />
<points value="0" />
</position>
</leaguetable>
wprjr
06-21-2007, 06:55 PM
Thanks, I'll give that a try in a bit. I finally got it to display using if(empty($val)).... You just don't think of those things when half asleep. :)
Thanks again for the help!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.