1
votes
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->xmlStandalone = true;
$doc->loadXML($error);
echo $doc->saveXML();

Output

<?xml version="1.0"?>
<error status="fatal" httpResponseCode="500" httpResponseMessage="Internal Server Error">
        <errorType>InternalServerError</errorType>
        <errorServer>FeedServer</errorServer>
        <errorMessage>Failed to process GetFeed request</errorMessage>
        <friendlyMessage/>
        <innerMessage>No permitted outlet found</innerMessage>
</error>

I need the XML output should show the encoding="UTF-8" along with the version="1.0" Please help...

AFTER FIXED.....

$doc    = new DOMDocument('1.0', 'UTF-8');
$doc->loadXML($error);
$doc->xmlStandalone = true;
$doc->encoding = 'UTF-8';
echo $doc->saveXML(); 

THE DESIRED OUTPUT...

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error status="fatal" httpResponseCode="500" httpResponseMessage="Internal Server Error">
        <errorType>InternalServerError</errorType>
        <errorServer>FeedServer</errorServer>
        <errorMessage>Failed to process GetFeed request</errorMessage>
        <friendlyMessage/>
        <innerMessage>No permitted outlet found</innerMessage>
</error>
1
Thanks for reply. I have got some good ideas about XMLDOM from your link but my problem is not solved yet. I tried a number of things from here.. - Devasish

1 Answers

2
votes

The parameters in the new DOMDocument constructor are overwritten with the values from the loaded XML document when loadXML is called.

If you set the encoding of the output document (e.g. $doc->encoding = 'UTF-8', before calling saveXML), it should be added to the XML declaration.