Solved

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

Posted on 2008-06-09
2
221 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
ID: 21746361
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
ID: 31465544
Superb, and easy when you know how!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Keep getting 503 on Curl request 6 30
Create new password with id in link 5 25
Saving image into server to get url later 1 31
Scope of $_SESSION 17 27
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

919 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

19 Experts available now in Live!

Get 1:1 Help Now