![](/img/trans.png)
[英]Get value from xml node with namespace with colon using PHP DOMDocument
[英]XML parsing, get 'rel' value from link using PHP DOMDocument
我在用PHP分析XML链接时遇到了麻烦。
我知道提取必须很简单,但是我找不到任何直接的要点文档。
XML格式
<entry>
<title type="html">Some title</title>
<id>tag:url.com,2012-03-08:/dir/id/11</id>
<link rel="alternate" type="text/html" href="http://someLink.com/?id=11" />
<content type="html">
Some content
</content>
</entry>
的PHP
$contents = $x->getElementsByTagName( "content" );
$content = $contents->item(0)->nodeValue;
$links= $x->getElementsByTagName( "link" );
$link = $links->item(0)->nodeValue;
我可以得到的内容例如:
echo $content;
输出“某些内容”
但是我找不到链接的rel标签。
我知道如何使用jQuery来做到这一点,但是我想要一个将在服务器端生成的解决方案,因此我可以更轻松地对其进行缓存。
谢谢
您可以使用DOMElement :: getAttribute获得'rel'属性:
$links = $x->getElementsByTagName('link');
$link = $links->item(0)->getAttribute('rel');
echo $link;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.