homepage Welcome to WebmasterWorld Guest from 54.161.166.171
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 / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
php curl as xml to db
how to create an xml parser
artgraven




msg:4101847
 12:26 pm on Mar 21, 2010 (gmt 0)

Hi all.
Glad to have found the community.
I have a technical issue with curl
I am using it to consume a web service
essentially i am sending an http with a set of get variables that then it returns an xml page which is then stored in the $output variable.

what i cannot figure and i know this is very novice of me is how to i get out the specific values i need from the xml.

for instance i can echo it out and it strips the xml or i can use htmlentities in which case it shows the content with the xml but what i don't know is how can i extract specific values from the xml.

I assume i need to parse the xml somehow using simplexml or domxml but i don't fully understand how.

i am familiar with how to do this in for instance actionscript but not in php.

any advise would be very helpful.

I am building a credit check application and i need to store into a mysql database the users negative credit matches in the xml

here is an example of my amateur code

// create curl resource
$ch = curl_init();

// set url
curl_setopt($ch, CURLOPT_URL, "$url");

//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// $output contains the output string
$output = curl_exec($ch);

//echo $output;
echo htmlentities($output);

// failed attempt to use xml
//$doc = new DOMDocument();
//$doc->loadXML($output);
//$responseNode = //$doc->getElementsByTagName("isValidPost")->Name(0);
//echo $responseNode;
// end of failed attempt


// close curl resource to free up system resources
curl_close($ch);

thanks in advance i am glad to have found this place

 

gsmith




msg:4101938
 6:04 pm on Mar 21, 2010 (gmt 0)

There might very well be a better way to do this, but recently I had to do something very similar, and used the XMLReader class in order to parse the XML down to the level where the data elements that I needed appeared, and then used the Perl-Compatible Regular Expressions function preg_match() to read the required values.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
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