【问题标题】:How to get value of attribute of tag using php SimpleXML?如何使用 php SimpleXML 获取标签属性的值?
【发布时间】:2014-08-03 03:50:40
【问题描述】:

(没关系,我已经找到了解决方案)

我知道如何解析 XML 文件,但这是我第一次遇到带有内联值的东西

<?xml version="1.0" encoding="iso-8859-1"?>
<imginfo xmlns="http://ns.xxxxxxxx.com/12/" version="8" timestamp="1406951709">
    <files server="540" rownumber="8376">
        <image size="177" content-type="image/jpeg">sample_name_here.jpg</image>
    </files>
    <resolution>
        <width>800</width>
        <height>486</height>
    </resolution>
</imginfo>

如何提取server 的值,在这种情况下该值为540(使用PHP 的SimpleXMLElement

【问题讨论】:

标签: php xml dom xml-parsing attributes


【解决方案1】:
NodeList nl1= docEle.getElementsByTagName("files");// Accesses the files block
if(nl != null && nl.getLength() > 0) {
for(int i = 0 ; i < nl.getLength();i++) {
    Element el = (Element)nl.item(i);
    String s=el.getAttribute("server");
}

getAttribute 函数是提取 xml 中的内联值的关键。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-14
    • 2018-08-04
    • 2012-05-19
    • 2011-09-17
    • 1970-01-01
    • 2012-10-03
    • 2015-02-26
    相关资源
    最近更新 更多