如何使用 PHP 的 DOM Parser 从 XML 中提取节点属性 [英] How to extract a node attribute from XML using PHP's DOM Parser

查看:31
本文介绍了如何使用 PHP 的 DOM Parser 从 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']."
";

输出:

http://www.thesite.com/download/eysjkss.zip

这篇关于如何使用 PHP 的 DOM Parser 从 XML 中提取节点属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆