我有这样的 XML
<atom:feed xmlns="http://kosapi.feld.cvut.cz/schema/3" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:osearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:base="https://kosapi.fit.cvut.cz/api/3/" xml:lang="cs">
<atom:entry>
<atom:id>urn:cvut:kos:parallel:353810000</atom:id>
<atom:updated>2013-06-02T14:15:54.0</atom:updated>
<atom:author>
<atom:name>kalvotom</atom:name>
</atom:author>
<atom:link rel="self" href="parallels/353810000/"/>
<atom:content atom:type="xml" xsi:type="parallel">
<capacity>24</capacity>
<capacityOverfill>DENIED</capacityOverfill>
<code>101</code>
<course xlink:href="courses/BI-EFA/">Efektivní algoritmy</course>
<enrollment>DENIED</enrollment>
<occupied>0</occupied>
<parallelType>TUTORIAL</parallelType>
<semester xlink:href="semesters/B131/">Zimní 2013/2014</semester>
<timetableSlot>
<day>2</day>
<duration>2</duration>
<firstHour>1</firstHour>
<parity>BOTH</parity>
<room xlink:href="rooms/T9:346/">T9:346</room>
</timetableSlot>
</atom:content>
</atom:entry>
</atom:feed>
我正在编写一个 PHP 脚本,需要提取<capacity>
,<occupied>
和<enrollment>
每个标签的内容<atom:entry>
(实际上有多个<atom:entry>
标签)。现在,我查找了一些关于如何处理名称空间的提示,但仍然无法使其工作。我的代码
$xml = simplexml_load_file("someurl");
$xml->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom');
foreach($xml->xpath("//prefix:entry") as $entry) {
$entry->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom');
$content = $entry->xpath("//prefix:content");
echo $content->enrollment . " | " . $content->occupied . "/" . $content->capacity . "<br />\n";
}
我明白了
注意:试图获取非对象的属性