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

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

Is it a good practice to store user info. in sessions?
I am making a user class for my script which stores all the user information in sessions. It takes u

PHP Code To Change Font Color in Table Cell
I would appreciate help with the following snippet of my php code. I am just trying to change the f

why this query can delete duplicates ?
why this query can delete duplicates ? Anybody can give me the detailed explanation ?

Tha

Referential Integrity problem when inserting into 2 tables at same time
Hello Everyone,

Im relativity new to PHP and MySQL and i have come up against a problem. i h

RadioButtonList data selection
view plaincopy to clipboardprint?

onclick problem
I have <input type="text" name="message">
<a href=page2.

ECC6 - Single sign-on
We are in the process of upgrading to ECC 6 which will support single sign on with user passwords al

'210010106140040100' == '210010106140040101'
Debugging this simple line of a PHP script

Code: if($a == $b){ }
I've found that with val

PayPal Redirect Issue
When I have my paypal button set so that is redirects to http://empiremarketing.ca/order.php,it work

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