【发布时间】:2019-02-24 13:53:33
【问题描述】:
试图在如下所示的 XML 文件中查找特定节点:
<?xml version="1.0" encoding="utf-8"?>
<disqus xmlns="http://disqus.com" xmlns:dsq="http://disqus.com/disqus-internals"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://disqus.com/api/schemas/1.0/disqus.xsd http://disqus.com/api/schemas/1.0/disqus-internals.xsd">
<post dsq:id="2248389859">
<id/>
<message><![CDATA[<p>Message</p>]]></message>
<createdAt>2015-09-11T17:08:10Z</createdAt>
<isDeleted>false</isDeleted>
<isSpam>false</isSpam>
<author>
<name>author</name>
<isAnonymous>false</isAnonymous>
<username>author</username>
</author>
<thread dsq:id="3828540236"/>
<parent dsq:id="2246284031"/>
</post>
</disqus>
我想通过 SimpleXML#xpath 方法找到post,更具体地说是通过thread dsq:id 属性。但我什至找不到线程本身
$xml = simplexml_load_file("file.xml")
var_dump($xml->xpath('/disqus');
这会打印一个空数组 - 但为什么呢?
【问题讨论】:
标签: php