PHP:使用SimpleXML访问命名空间XML

时间:2010-06-07 17:45:00

标签: php xml namespaces simplexml

我正在使用simplexml()函数来解析RSS提要,而我可以访问$var->title<title>如何访问<dcterms:issued>

Feed摘录(http://pastebin.com/nN8G78AH):

<item rdf:about="http://newyork.craigslist.org/brk/mcy/1779690213.html">
  <title><![CDATA[Kawasaki ZX-10R Rims For Sale (Nassau Motorsports)]]></title>
  <link>http://newyork.craigslist.org/brk/mcy/1779690213.html</link>
  <description><![CDATA[
<br>

<br>
2000 KAWASAKI ZX-12R
<br>

<br>
FRONT & REAR RIMS W/FRONT & REAR ROTORS
<br>

<br>
RIMS ARE IN BOLT ON CONDITION .. RIM ARE CHARCOAL BLACK .. ASKING 400.00 OBO
<br>

<br>
CALL 516-216-5768 FOR MORE INFO]]></description>
  <dc:date>2010-06-07T13:04:07-04:00</dc:date>
  <dc:language>en-us</dc:language>
  <dc:rights>Copyright &#x26;copy; 2010 craigslist, inc.</dc:rights>
  <dc:source>http://newyork.craigslist.org/brk/mcy/1779690213.html</dc:source>
  <dc:title><![CDATA[Kawasaki ZX-10R Rims For Sale (Nassau Motorsports)]]></dc:title>
  <dc:type>text</dc:type>
  <dcterms:issued>2010-06-07T13:04:07-04:00</dcterms:issued>
</item>

1 个答案:

答案 0 :(得分:2)

您使用的是SimpleXML吗?

您的解决方案似乎存在right here

修改

这里为了后人而复制的答案

通过XML名称空间访问子项。

$dcChildren = $node->children( 'http://purl.org/dc/elements/1.1/' );

$title = $dcChildren->title;