0

(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)

Mohammad
  • 21,175
  • 15
  • 55
  • 84
Mike'78
  • 51
  • 6
  • Possible duplicate of [How to get the value of an attribute from XML file in PHP?](http://stackoverflow.com/questions/1256796/how-to-get-the-value-of-an-attribute-from-xml-file-in-php) – Mohammad Oct 16 '16 at 18:57

1 Answers1

0
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.

Asher
  • 811
  • 3
  • 10
  • 19