1

I'm making a cURL request into an authenticated area which is working fine; and when echoing out the response everything looks good except for the first part. This is my exact response (with the otherData tag replacing my actual data).

 <?xml version='1.0' encoding='UTF-8'?>
    <Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <ResponseStatus>
           <StatusCode>0</StatusCode>
           <StatusMessage>Success</StatusMessage>
        </ResponseStatus>
        <otherData></otherData>
    </Response>

See how the xml version='1.0' encoding='utf-8' and then we switch to using " in the actual XML? When I'm trying to load this with simplexml_load_string it fails due to that. I know I could simply do a str_replace, however that isn't really understanding the full issue here.

1
  • The problem lies with whatever is returning the response. Maybe we can see how this is done to help? Btw, good on your for not taking the easy why out. Commented Jun 17, 2011 at 15:52

2 Answers 2

1

Can we see your php code? I'm running:

<?php
    $xml_string =<<<XML
<?xml version='1.0' encoding='UTF-8'?>
<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ResponseStatus>
       <StatusCode>0</StatusCode>
       <StatusMessage>Success</StatusMessage>
    </ResponseStatus>
    <otherData></otherData>
</Response>
XML;

$xml_obj = simplexml_load_string($xml_string);
echo $xml_obj->ResponseStatus->StatusMessage."\n";
?>

And it seems to work fine.

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

Comments

0

try replacing all " with '.

$string = str_replace("\"", "'", $string);

The string is being closed at the double quotes.

So the string is printing as

$string = "<?xml version='1.0' encoding='UTF-8'?><Response xmlns:xsi=" so obviously using str_replace() would turn that " it's closing on into a ' making the string correctly output.

1 Comment

another kinda bubble gum way of doing it though :/ I didn't know if this was something that normally was expected in a return and a clean way of handling it that didn't involve any kind of data replacing.

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.