如何使用PHP的DOM解析器从XML中提取节点属性 [英] How to extract a node attribute from XML using PHP's DOM Parser
本文介绍了如何使用PHP的DOM解析器从XML中提取节点属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从来没有真正使用DOM解析器,现在我有一个问题。
I've never really used the DOM parser before and now I have a question.
我如何从这个标记中提取URL:
How would I go about extracting the URL from this markup:
<files>
<file path="http://www.thesite.com/download/eysjkss.zip" title="File Name" />
</files>
推荐答案
使用simpleXML:
Using simpleXML:
$xml = new SimpleXMLElement($xmlstr);
echo $xml->file['path']."\n";
输出:
http://www.thesite.com/download/eysjkss.zip
这篇关于如何使用PHP的DOM解析器从XML中提取节点属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文