dongshao9106 2014-08-03 03:50 采纳率: 100%
浏览 47

如何使用php SimpleXML获取标签属性的值?

(Nevermind I already got the solution to this)

I know how to parse an XML file but this is the first time I encountered something with inline values

<?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>

How can I extract the value of the server in this case the value is 540 (using PHP's SimpleXMLElement)

  • 写回答

1条回答 默认 最新

  • douqi3064 2014-08-03 03:57
    关注
    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");
    }
    

    The getAttribute function is key here for extracting inline values in an xml.

    评论

报告相同问题?