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

Help with syntax
Hi all!

The $bridge variable is not getting passed while it is contained in the line below:

Greek characters in php
Hi,

I'm making a script and I m using for first time greek characters.
I started to write

Update Database
Hi All,


I have a problem with this:

Code: [Select]<?php
session_start();

Adding post count
How would I make it so everytime someone clicks submit on my form, their row in the database for the

Simple program to copy files between two computers over the web
I use logmein free and often need to move files between my two computers. Generally, I move the file

how do I show what a user have selected from a checkbox?
From my code below, how would i show which check boxes have been checked and which radio buttons sel

what business processes?
Hi,

A general question. What business processes (like OTC - Order to Cach, P2P, R2R etc)

Impact of movement type 412 E on MAP
Hi

Usage of movement type 412 E is causing huge change in MAP .

Is there any r

newbie question about multiple queries
hi everyone,
I'm sorry to ask such a basic question, but I'm young and trying to learn php on my

Navigation include for all site directories
Hi,

I need a navigation include that can deal with directories at different levels on a site.

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