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>
Did you know?Explore Trending and Topic pages for more stories like this.
<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
MASS PM
Hello all, I'm trying to send mass private messages to users in my database but keep getting an erro
error help - Dynamic Image
I've been working on making my site less cluttered in the directories and more secure lately. In an
Save username into DB
OkaY so I got my blog to actually save the posts and whatever, all I need now is for it to keep the
Problems with strings containing
Hey all,
I have encountered something strange in a script. I am trying to write an XML heade
Hi, explode and strstr.
Hi, I seem to be confused about the strstr function, eg. i have a string like:
"a.b.c.d.e.f&
How to set pass login name from htaccess to php
When the user logs into my members page via htaccess, I'd like to retain the username so that I can
login page does not execute a else statement
I've created a login page using sessions.
When an incorrect user name or password is entered then
Displaying Multidimensional Arrays...about to put my head in a vice, PLEASE HELP
I am fairly new to PHP and MySQL and I have a problem which I have been trying to resolve for days.
Linux socket programming
Where can I find a good introduction to socket programming?
Sql and php order list script problems
Hi im having a few problems with trying to get the coding right on a orders list ive done (or trying