Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-09
2
Medium Priority
?
237 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:Neil Thompson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 2000 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:Neil Thompson
ID: 31465544
Superb, and easy when you know how!
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.
Suggested Courses

604 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