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 Like 46 Dislike
Previous forums Next forums
Other forums

Splitting Attributes
SQL> SELECT I_NAME, substr(I_NAME,1,instr(I_NAME,'O')) "First part",

substr(I_NAME, IN

Random date selection
i want to select random date with time(hour+minutes+sec) where date is specified(10/22/2009) and tim

Thought I has this figured out especially after all the help i received?
Cags, Salathe, Daniel helped me with this yesterday, but not sure i took it all in.
I am attempti

Multi-image upload problems
Lets see if I can get some help on this one. Can anyone show me what I am doing wrong here. I'm just

include
Hi I have this way of licensing my PHP application, and I want to know if you guys can answer some q

Storing/displaying image urls in a database?
Hi
Basically I have the following scenario:
User chooses picture from list. Picture info is ad

Sales orders ans reservations not taken into account on MPS / MRP
Hello,

I am implementing the MPS / MRP and I have the following problem:

I ha

reading partial code from external site
Hi,

I am trying to write a script for my website to get an article from an external website.

records between 2 dates
Hello all,

I have a date tracked table which contains effective_start_date and effective

strptime() equivalent for php4 ?!
Greetings!

this is my first post, thank you in advance for your replies.

Well, the ti

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash