2

I'm trying to parse some xml using simplexml and php...it's being returned to me from a service like so:

<DMResponse><Code>2</Code><Description>Your request was successfully received You will        receive notification once the process has been completed.</Description><ResultData><Explanation>     The job name is 578bbn004 </Explanation></ResultData></DMResponse>

I pasted this from the .net panel in firebug.

This is how I'm trying to parse is using php:

$result = curl_exec($ch);
print 'xml ' . $result . ' xml';
$xml = new SimpleXMLElement($result);
$code = $xml->code;
echo $code;

$result is deinfitely populated...I get it back in the print statement above....it contains the xml structure I've posted.

The error I'm getting is 'String could not be parsed as XML'. I don't understand why it's doing this. Any ideas?

2 Answers 2

3

Try $xml = simplexml_load_string($result); ... I've never done it the way you're doing it. That's not to say that it won't work, though.

Edit: If simplexml_load_string() doesn't work, your string may contain some (nonprintable) invalid characters or something like that.

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

1 Comment

you can check your XML here : w3schools
1

To print your SimpleXML Object, you have to use $xml->asXML() (to print into a file $xml->asXML(file_name)).

If you still have an error : What is print when you add this code just after $xml = new SimpleXMLElement($result); ?

echo "<pre>";
var_dump($xml);
echo "</pre>";
die();

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.