xml element exists
Posted on
16th Feb 2014 07:03 pm by
admin
Code: [Select]<?xml version="1.0"?>
<Addresses>
<Address ID="1">
<Address2>101 MAIN ST</Address2>
<City>BIGTOWN</City>
<State>OH</State>
<Zip5>22222</Zip5>
<Zip4></Zip4></Address>
<Address ID="2">
<Address2>420 HIGH ST</Address2>
<City>MYTOWN</City>
<State>AK</State>
<Zip5>54321</Zip5>
<Zip4>2562</Zip4></Address>
</Addresses>
My code is reading the above xml, but if there was an error the xml will be different, for example:
Code: [Select]<?xml version="1.0"?>
<Addresses>
<Address ID="1">
<Error>
<Number>-2147219401</Number>
<Source>blah</Source>
<Description>Address Not Found. </Description>
<HelpFile></HelpFile>
<HelpContext>1000440</HelpContext>
</Error>
</Address>
<Address ID="2">
<Address2>420 HIGH ST</Address2>
<City>MYTOWN</City>
<State>AK</State>
<Zip5>54321</Zip5>
<Zip4>2562</Zip4></Address>
</Addresses>
Currently, I am accessing the elements like this:
$xml = new SimpleXMLElement($xml_txt);
$first_address = $xml->Address[0]->Address2;
$second_address = $xml->Address[1]->Address2;
This code doesn't work when the error xml is returned. There will always be 2 items in the xml. How can I tell which (if any) address has an 'error' node? Also, I need to know which of the 2 IDs has the error.
No comments posted yet
Your Answer:
Login to answer
159 46
Other forums
links using header()
Hi All
I'm not sure where to ask for help on this but I hope someone can offer some. I'm at
Simple PHP/Java Help..
Hi,
I'm trying to build a little program to do with calculating postage. Unfortunately i haven't
PHP error. Need help urgently
Hi,
I am programming a php site and have a problem that i just cant find out how to fix. When
Spaghetti Code
So.
I've pretty much reached the point where I have so many isset s on one page that I can't
want to add a break after a certain amount of characters
i was wondering how to add a break in a blog post after a certain amount of characters... any idea o
Operator precedence assistance.
I did a quick Google search and couldn't quite find the answer I wanted in terms I could understand,
whats wrong with my code please help!!!
this is the error
Warning: mysql_close(): supplied argument is not a valid MySQL-Link res
Executing an exe
Hi. I have some bizarre problem with exec (other any other method) to launch exe's. I am making a ga
Print out contents of to Excel
I have got this script that gathers all the data that I need but I need it to send it to excel inste
Not Loading Function Into Div
I'm not sure whether to put this under the php forum or ajax forum but because I tink it's more of a