我如何解析像这个例子的元素
<?php
$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
<movie>
<title>PHP: Behind the Parser</title>
<characters>
<character>
<name>Ms. Coder</name>
<actor>Onlivia Actora</actor>
<actor:view id='44' />
</character>
<character>
<name>Mr. Coder</name>
<actor>El ActÓr</actor>
<actor:view id='49' />
</character>
</characters>
<plot>
So, this language. It's like, a programming language. Or is it a
scripting language? All is revealed in this thrilling horror spoof
of a documentary.
</plot>
<great-lines>
<line>PHP solves all my web problems</line>
</great-lines>
<rating type="thumbs">7</rating>
<rating type="stars">5</rating>
</movie>
</movies>
XML;
$simpleXml = new SimpleXMLElement($xmlstr);
var_dump((array) $simpleXml);
名称空间错误:第35行/home/sweb/www/tmp/sxml.php中未定义视图上的名称空间前缀actor
第35行/home/sweb/www/tmp/sxml.php中的
答案 0 :(得分:3)
XML解析器依赖于事实文档必须严格有效,而您的文档格式不正确。它需要actor
的名称空间URI。根元素应该是这样的:
<movies xmlns:actor="http://yoururl.com/">
只要您没有,没有合规的XML解析器会接受您的文档。