0

Please view the below code

$xml_string = "<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
    <soapenv:Body>
        <res:ResultMsg xmlns:res='http://cps.huawei.com/cpsinterface/result'>
            <![CDATA[
            <?xml version='1.0' encoding='utf-8'?><Result><ResultParameters><ResultParameter><Key>FailedReason</Key><Value>The value 611015125123 of the CNIC parameter is incorrect, failed to authenticate the parameter.</Value></ResultParameter></ResultParameters><ResultCode>2002</ResultCode><ResultType>0</ResultType><OriginatorConversationID>20180904165750</OriginatorConversationID><ResultDesc>Transaction information is invalid.</ResultDesc><TransactionID>000000000000</TransactionID><ConversationID>AG_20180904_00007be9004e56992e5f</ConversationID></Result>]]>
</res:ResultMsg>
</soapenv:Body>
</soapenv:Envelope>";

Then I get the type of Variable

$type=gettype($xml_string);

echo string alright. When I Try to echo the actual Value, it just print out a part of it.

FailedReasonThe value 611015125123 of the CNIC parameter is incorrect, failed to authenticate the parameter.2002020180904165750Transaction information is invalid.000000000000AG_20180904_00007be9004e56992e5f]]>

Why is this strange behavior happening. I tried replacing all the new line characters as well, but it didn't help. Any hints are appreciated.

1
  • 1
    "When I Try to echo the actual Value" In a browser? View the source and see if it's all there. Or output it between a <textarea></textarea>. Or use CLI to print it out Commented Sep 5, 2018 at 12:21

2 Answers 2

1

Stupid mistake at my end, Answering in case someone stumbles upon this issue.As per the comment to my question all I had full data but it, wasn't shown by browser because of tags.

 echo "<textarea>";
           echo $manual ;     
 echo "</textarea>";

did the job.

Sign up to request clarification or add additional context in comments.

1 Comment

Other ways to output the XML raw: echo htmlspecialchars($manual); to escape the <, >, and & characters; or, header('Content-Type: text/plain'); to tell the browser not to parse any HTML on the page.
0
$regex = '#<Value>(.*?)</Value>#';
$code = preg_match($regex, $xml_string, $matches);

echo $matches[0];

You can try this way. It's not an xml parse, it's more of a php/regex approach but will do the work for you.

The output is : The value 611015125123 of the CNIC parameter is incorrect, failed to authenticate the parameter.

I also run on the same problem as you did with parsing this soap-xml response so i thought of this work around that works. After all it's a string type and php has really nice tools to parse strings using regex.

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.