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>2006030 1</Date>
</Item>
<Item>
<Type>Trans</Type>
<Code>BTL</Code>
<Date>2006030 1</Date>
</Item>
<Item>
<Type>Sight</Type>
<Code>HTL</Code>
<Date>2006030 1</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 <Codeand the <Dateonly where the <Typeis
"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</CodeDOES Exist ) and the ' else '???
the name $url.
//valid xml format
<Trip>
<Item>
<Type>Trans</Type>
<Code>KAP</Code>
<Date>2006030 1</Date>
</Item>
<Item>
<Type>Trans</Type>
<Code>BTL</Code>
<Date>2006030 1</Date>
</Item>
<Item>
<Type>Sight</Type>
<Code>HTL</Code>
<Date>2006030 1</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 <Codeand the <Dateonly where the <Typeis
"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</CodeDOES Exist ) and the ' else '???
Comment