Solved

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

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

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 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