homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

XML with PHP5.3 extract data - newbie

Msg#: 4316775 posted 9:24 am on May 24, 2011 (gmt 0)

Hi, please forgive my ignorance but i am new to XML and its interaction with PHP5.3. I have experimented with simpleXMLElement but can only seem to extract data from the very top level of the data returned i.e. Transaction and Code. Perhaps i am up a gumtree!

All i need to get is the reply data to SMStext messages sent via a SMStext webservice. The data will then via PHP be fed back into the MYSQL database that logs outgoing and incoming SMS messages. The XML reply is in this format below. I have visited several web help pages but i am floundering. Just a simple line of code to loop through any replies would be most helpful.
Any ideas please?

Many thanks, an XML newbie!

<Description>Transaction OK</Description>
<Body>hello world</Body>
<Body>Hello world</Body>

[edited by: httpwebwitch at 1:26 pm (utc) on May 24, 2011]
[edit reason] removed phone numbers from the example [/edit]



WebmasterWorld Administrator httpwebwitch us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4316775 posted 1:39 pm on May 24, 2011 (gmt 0)

once you've created your SimpleXML object, use print_r() to see its structure.

$obj = simplexml_load_string($xml);

that method works well in cases like yours where you're not accessing data inside XML attributes and element values. When your data has mixed attributes and values, print_r() is ineffective because it converts your objects into arrays first. There's an explanation here:
[php.net...] and more good examples here: [php.net...]

Once you view the structure using print_r(), it should be easy to see how you get to the innards.

Something like this might work:

foreach ($obj->GetSMSReplyResponse->Replies->Reply as $reply) {
echo $reply->Body;


Msg#: 4316775 posted 5:50 pm on May 24, 2011 (gmt 0)

Many thanks, I'll look at this later.PH.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved