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

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

Displaying returned XML in another PHP page
I have an online payment form that will return XML given if a payment is successful or declines. I

code help - pagination
Hi all, I have this code, basically a user logs into my site and they get this page.

The pro

Is STL important?
I'm just starting programming and I've made it until the Standart Template Library. But the chapter

Request-URI Too Large
I have created a simple submit form for a mysql database that puts a piece of code into database.<

Query failed issue with php script but works fine in mssql manager!
hi i have the script below which copies data from one table to another but will only insert new data

help with calculations on a flat text file
hello,
I have this code below that is attached to a flat file like this:
Email:LastName:FirstN

ClientScript.RegisterClientScriptBlock Issue
This is what I haveview plaincopy to clipboardprint?Protected Sub posrback_Click(ByVal sender As Obj

How to clone an SAP ECC using bacup tape on z/os?
We want to clone our production to a different SID using backup tape.

How to show more than 1 users with this code...
Hello,
i have a table that shows users only if I, as Administrator, want to be shown. But its sho

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