Posted by php_Boi on 02/01/07 01:47
i have a document with this structure. that is loaded from a file with
the name $url.
//valid xml format
<Trip>
<Item>
<Type>Trans</Type>
<Code>KAP</Code>
<Date>20060301</Date>
</Item>
<Item>
<Type>Trans</Type>
<Code>BTL</Code>
<Date>20060301</Date>
</Item>
<Item>
<Type>Sight</Type>
<Code>HTL</Code>
<Date>20060301</Date>
</Item>
</Trip>
Now to get the values of all the items i can do simply enough with
foreach ($url>Trip->Item as $transfer)
{
$vType = $transfer->Type;
$vCode = $transfer->Code;
}
But i need to perform a slightly more complex query.
i need to get the the <Code> and the <Date> only where the <Type> is
"Sight"
tried this but didnt have any luck. (casted as a string so tag wasnt
assumed to be an object)
if ((string) $url->Code == 'Sight') {
print 'Success.';
}
else if((string) $url->Code == 'Trans') {
print 'Success.';
}
else print 'Oh no!';
which will recognize the first node but ignore the ' else if ' (the
node where <Code>Trans</Code> DOES Exist ) and the ' else '???
Navigation:
[Reply to this message]
|