Answer the question
In order to leave comments, you need to log in
Why is SimpleXMLElement throwing char out of range?
Hello!
Can anyone come across
this code
$xmlSign = new SimpleXMLElement("<?xml version=\"1.0\"?><data></data>");
$xml_user_info->addChild("$key",htmlspecialchars("$value"));
return $xmlSign->asXML();
SimpleXMLElement::asXML(): xmlEscapeEntities : char out of range
$xmlSign = new SimpleXMLElement("<?xml version=\"1.0\" encoding="UTF-8" standalone="yes"?><data></data>");
$xml_user_info->addChild("$key",htmlspecialchars("$value"));
return $xmlSign->asXML();
org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 877; An invalid XML character (Unicode: 0x1) was found in the element content of the document.
$xmlPlain = $xmlSign->asXML();
return htmlentities($xmlPlain, ENT_QUOTES | ENT_IGNORE, "UTF-8");
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 2; Reference is not allowed in prolog.
Answer the question
In order to leave comments, you need to log in
If I understood correctly
<?php
$xmlSign = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><data/>');
$xml_user_info = $xmlSign->addChild('user', 'admin');
echo $xmlSign->asXML();
<?xml version="1.0" encoding="UTF-8"?>
<data><user>admin</user></data>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question