I'm trying to load an XML file from a URL using SimpleXMLElement.
My code basically looks like this:
$xml = new SimpleXMLElement($url, null, true);
$url is the string of the URL containing XML response. I can load it just fine if there is no "xmlns" in the XML. When there is "xmlns", it'll cause runtime error:
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: http://test.cloudapp.net:8080/api/missiondetails/1:1: parser error : Start tag expected, '<' not found in /var/www/test.com/test.php on line 10
This is the example of the XML format:
<MissionDetails xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Test.DataTransferObject"></Mission>
Anybody knows how to load XML with "xmlns" in the root node?
Thanks beforehand.
What version of PHP are you using? The data_is_url
(3rd) argument for the SimpleXMLElement
constructor was only added in 5.1.2.
Also, the second argument should be an integer, 0
by default.
Perhaps try using simplexml_load_file()
instead
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.