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

2022-01-14 00:00:00 xml namespaces php simplexml

我正在使用 simplexml() 函数来解析 RSS 提要,而我可以访问 $var->title</code> 我如何访问<code><dcterms:issued></code>?<em class="showen"></p> <p class="en">I'm using simplexml() function to parse through RSS feed, while i can access <code>$var->title</code> to <code><title></code> how do I access <code><dcterms:issued></code>?</p> <p class="cn">提要摘录(http://pastebin.com/nN8G78AH):</p> <pre><code><code><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> </code></code></pre> <p class="cn"></p> <h3 class="best_ans mt-1">推荐答案</h3> <p class="cn">你在使用 SimpleXML 吗?<em class="showen"></p> <p class="en">Are you using SimpleXML? </p> <p class="cn">似乎存在适合您的解决方案就在这里.<em class="showen"></p> <p class="en">A solution for you seems to exist right here.</p> <p class="cn">为了子孙后代,这里复制了答案</p> <p class="cn">通过它们的 XML 命名空间访问子级.<em class="showen"></p> <p class="en">Access the children by their XML namespace.</p> <pre><code><code>$dcChildren = $node->children( 'http://purl.org/dc/elements/1.1/' ); $title = $dcChildren->title; </code></code></pre> </div> <div class=""> <p><strong>相关文章</strong></p> </div> </article> </div> </main> <footer> <div class="container"> <p> <span>友情链接:</span> <a href="https://www.688576.com" target="_blank">雨伦博客</a>   <a href="https://www.yaanbbs.net" target="_blank">雅安论坛</a> </p> <a href="https://beian.miit.gov.cn" target="_blank">京ICP备15023317号-6</a> </div> </footer> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?30b42218aa13759c43de5f1971d0a93b"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>