speedy33417 Posted August 17, 2009 Share Posted August 17, 2009 I'm working on a website that deals with an xml response. After an application is filled out on our website we get a response sent to us in $result If the application is approved then it looks something like this: <tss_loan_response><signature><data name="page">app_completed</data><data name="site_type">soap_oc</data><data name="license_key">sample</data><data name="promo_id">99999</data><data name="promo_sub_code"/></signature><errors/><content><section><verbiage><![CDATA[<br/> <p>Thank you for your application. You have been approved. Please click <b><a href="http://www.somesite.com">here</a></b>to complete your application.</p><p>You will be automatically sent to the page in a few seconds.</p><script type="text/javascript"> var script_expression = "document.location.href = 'http://www.somesite.com'"; var msecs = 2 * 1000; setTimeout(script_expression, msecs);</script> ]]></verbiage></section></content></tss_loan_response> I need pieces of code from the $result 1. The code between <data name="page"> and </data> 2. The code between <![CDATA[ and ]]> How would I get them in $page and $data??? Quote Link to comment https://forums.phpfreaks.com/topic/170695-php-xml-help/ Share on other sites More sharing options...
DarkendSoul Posted August 17, 2009 Share Posted August 17, 2009 I'd write you out something but I'm really tired right now and I'm going to bed. But here's a tutorial that should help you a lot. http://www.phpfreaks.com/tutorial/handling-xml-data You'll probably have to use $tss_loan_response->content->section->verbiage for the cdata. Quote Link to comment https://forums.phpfreaks.com/topic/170695-php-xml-help/#findComment-900270 Share on other sites More sharing options...
speedy33417 Posted August 17, 2009 Author Share Posted August 17, 2009 Thanks Darken. I looked at the tutorial, but it's still not clear how I can get those two pieces of code that I need to display for the applicant. I've never dealt with XML and it's totally new territory for me. I was hoping that I could maybe use regex to fish out the part that I need or any simple solution that would load the required part of the script into my variables. Anybody else, pleeeeeeaaaaase? Quote Link to comment https://forums.phpfreaks.com/topic/170695-php-xml-help/#findComment-900274 Share on other sites More sharing options...
DarkendSoul Posted August 17, 2009 Share Posted August 17, 2009 Try this out. >.< Kept thinking about it in bed. $xml = SimpleXMLElement($xmlfile, null, true); echo "Data: " . $xml->xpath("tss_loan_response/data[@name=\"site_type\"]")->nodeValue . "<br />\n"; echo "CData: " . $xml->tss_loan_response->content->section->verbiage->nodeValue; Quote Link to comment https://forums.phpfreaks.com/topic/170695-php-xml-help/#findComment-900284 Share on other sites More sharing options...
DarkendSoul Posted August 17, 2009 Share Posted August 17, 2009 Oops, I don't think you need nodeValues for simplexml :x Quote Link to comment https://forums.phpfreaks.com/topic/170695-php-xml-help/#findComment-900293 Share on other sites More sharing options...
speedy33417 Posted August 17, 2009 Author Share Posted August 17, 2009 Notice: Undefined variable: result in /hsphere/local/home/somesite.com/posting5.php on line 172 Fatal error: Call to undefined function simplexmlelement() in /hsphere/local/home/somesite.com/posting5.php on line 174 Quote Link to comment https://forums.phpfreaks.com/topic/170695-php-xml-help/#findComment-900364 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.