Solved

convert this xml result into $var - $val for use later

Posted on 2008-06-09
2
220 Views
Last Modified: 2010-04-21
Hi

I have a xml reply atteched that I need to be able to access the ariables and values later in my code. How can I cast these to perhaps a $var->$val scenario.

eg:
$Status = 5;
$Reason = "Unable to authorise transaction at this time";

Neil
<?xml version="1.0"?>

<Response xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">

<Status>5</Status>

<Reason>Unable to authorise transaction at this time</Reason>

<FailReasonCode>-2147220303</FailReasonCode>

<FailReason>Invalid Input Data (XML document must have a top level element.).</FailReason>

<UserTxnReference></UserTxnReference>

<PaymentReference>3B5QBS284V5H</PaymentReference>

</Response>

Open in new window

0
Comment
Question by:NeilT
2 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
Comment Utility
You can use simpleXML for that like:
<?php
 

$XML = <<<XML

<?xml version="1.0"?>

<Response xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">

<Status>5</Status>

<Reason>Unable to authorise transaction at this time</Reason>

<FailReasonCode>-2147220303</FailReasonCode>

<FailReason>Invalid Input Data (XML document must have a top level element.).</FailReason>

<UserTxnReference></UserTxnReference>

<PaymentReference>3B5QBS284V5H</PaymentReference>

</Response>

XML;
 

$xml = simplexml_load_string($XML);

$status = (string) $xml->Status;

$reason = (string) $xml->Reason;

Open in new window

0
 
LVL 3

Author Closing Comment

by:NeilT
Comment Utility
Superb, and easy when you know how!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now