1

I have the following string:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/UKash/Service1"><UKashTransaction><txCode>99</txCode><txDescription>Failed</txDescription><settleAmount> <settleAmount><transactionId>1341481253EDFC871620</transactionId><changeIssueVoucherNumber> <changeIssueVoucherNumber><changeIssueVoucherCurr> <changeIssueVoucherCurr><changeIssueAmount> <changeIssueAmount><changeIssueExpiryDate> <changeIssueExpiryDate><ukashTransactionId> <ukashTransactionId><currencyConversion> <currencyConversion><errCode>219</errCode><errDescription>Invalid Voucher Number</errDescription> <UKashTransaction></string></xml>

And I want to get some attributes of that string, like txDescrition, and so on, I tried different variations but can't get result. I am using php, if anyone can help I will really appreciate it since I am blocked.

UPDATE:

Problem is that I do not format string to be valid so I use curl and this is what I am getting from the gateway:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/UKash/Service1">&lt;UKashTransaction&gt;&lt;txCode&gt;99&lt;/txCode&gt;&lt;txDescription&gt;Failed&lt;/txDescription&gt;&lt;settleAmount&gt;&lt;/settleAmount&gt;&lt;transactionId&gt;13414821393ED286BF2A&lt;/transactionId&gt;&lt;changeIssueVoucherNumber&gt;&lt;/changeIssueVoucherNumber&gt;&lt;changeIssueVoucherCurr&gt;&lt;/changeIssueVoucherCurr&gt;&lt;changeIssueAmount&gt;&lt;/changeIssueAmount&gt;&lt;changeIssueExpiryDate&gt;&lt;/changeIssueExpiryDate&gt;&lt;ukashTransactionId&gt;&lt;/ukashTransactionId&gt;&lt;currencyConversion&gt;&lt;/currencyConversion&gt;&lt;errCode&gt;219&lt;/errCode&gt;&lt;errDescription&gt;Invalid Voucher Number&lt;/errDescription&gt;&lt;/UKashTransaction&gt;</string>

Tnx.

2 Answers 2

1

Your XML is not well-formed - It's ending with a </xml> for which there's no starting <xml> element. Assuming you are correcting that, below code will solve your problem.

$xml = simplexml_load_string($string);
print_r($xml->txDescrition);
Sign up to request clarification or add additional context in comments.

2 Comments

yeap, it's not valid, since I'm getting strange info from gateway, do u know how to format it well ?
Use htmlspecialchars_decode() to decode the XML escape characters.
0

If you have Simple XML (PHP should have it enabled by default), try this:

$xmlObject = simplexml_load_string($string);
echo $xmlObject->txDescription;

http://www.php.net/manual/en/function.simplexml-load-string.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.