开发者

How to use an XML string to find certain element values in php?

How to use an XML string to find its certain element values? i used this code:

    10: $php_var = json_decode($json, 1);
    11  $serializer=new XML_Serializer();
    12: if($serializer->serialize($php_var))
    13: xml_string=htmlspecialchars($serializer->getSerializedData()); 
    14: echo $xml_string;
    15: $xml_obj = new DOMDocument();
    16: $xml_obj->loadXML($xml_string);
    17: $urls=$xml_obj->getElementsByTagName('url');

but it doesnt work and i got a Warning: DOMDocument::loadXML() [domdocument.loadxml]: Start tag expected, '<' not found in Entity, line: 1 in /var/www/seo-tool/get_details.php on line 15开发者_开发百科


What's that htmlspecialchars()? that function converts all the < and > to &lt; and &gt; and the xml is no longer xml.

Remove that call. if you want to echo the XML, do echo htmlspecialchars($xml_string) but don't store it in the variable.


Old was:
The XML you posted seems to be valid.

But you are missing the XML declaration, at the beginning of the string:

<?xml version="1.0" encoding="UTF-8" ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜