Better Solution needed!
| From: | callen | Date: | Tue, 21 Nov 2000 17:33:14 +0000 |
| Subject: | Better Solution needed! | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-26485@lists.php.net to get a copy of this message | ||
Hola:
Currently I am utilizing an if statement based upon count of the number
of tags parsed in xml data to determine if I have reached
the right tag. The tag <CMDTYCLASS> comes up 2 times in the same
documnet with different values. Furthermore, each CMDTYCLASS is encased
by a seperate ITEM tag: such that the xml looks like this:
<Item>
<CmdtyClass>100</CmdtyClass>
<Weight unit="lbs">245</Weight>
<Rate currency="USD">48.49</Rate>
<Charge currency="USD">118.80</Charge>
</Item>
<Item>
<CmdtyClass>200</CmdtyClass>
<Weight unit="lbs">245</Weight>
<Rate currency="USD">96.98</Rate>
<Charge currency="USD">237.60</Charge>
</Item>
The code that I use looks like this:
... (inside a function called from endElement() )
$i++;
$transit_time = $temp ['TRANSITTIME'];
$d_zip = $temp ['DESTINATIONZIP'];
$o_zip = $temp ['ORIGINZIP'];
$g_available = $temp ['GUARANTEEDAVAILABLE'];
if ($i ==7) {
$cmdty_class1 = $temp ['CMDTYCLASS'];
}
$cmdty_class2 = $temp['CMDTYCLASS'];
...
echo "Transit Time is: $transit_time <br>";
echo "Destination Zip is: $d_zip <br>";
echo "Origin Zip is: $o_zip <br>";
echo "Guaranteed Available? $g_available <br>";
echo "Commdity Class1 is: $cmdty_class1 <br>";
echo "Commdity Class2 is: $cmdty_class2 <br><br> hola<br>";
Although it works, this to me seems rather foolish. Is there any way in
which to varibalize(sp?) duplicate tags so that they have a unique
variable name such that I can latter manipulate them further?
--
Christopher C.M. Allen