By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,053 Members | 1,125 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,053 IT Pros & Developers. It's quick & easy.

SimpleXml Query

P: n/a
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 <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 '???

Feb 1 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Jan 31, 5:47 pm, "php_Boi" <timan...@gmail.comwrote:
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 <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 '???
Appology in Advance, typo i meant
if ((string) $url->Code == 'Sight') {
print 'Success.';}

else if((string) $url->Code == 'Trans') {
print 'Failure.';}

else print 'Oh no!';

Feb 1 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.