Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java xml element get attribute value

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

public class Demo {

    public static void main(String[] args) throws Exception {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document document = db.parse(new File("input.xml"));
        NodeList nodeList = document.getElementsByTagName("Item");
        for(int x=0,size= nodeList.getLength(); x<size; x++) {
            System.out.println(nodeList.item(x).getAttributes().getNamedItem("name").getNodeValue());
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: algorithm to know if a number is an integer 
Java :: java create an instance of a stack 
Java :: binary number input in int java 
Java :: Implementing the Vector Class in java list 
Java :: jackson deserialization fail-on-unknown-properties true 
Java :: android java how to stop activity from opening twice programatically 
Java :: make quotation a string 
Java :: single linked list in java 
Java :: export java path in ubuntu 
Java :: android select video samsung stackoverflow 
Java :: split on . in java 
Java :: java change frame border 
Java :: Send keybord key P in selenium java 
Java :: java string reduce 
Java :: java use space in enums 
Java :: retrofit post body 
Java :: the diameter of a binary tree 
Java :: java resultset to table 
Java :: refresh sharedpreferences going back java 
Java :: java list iterator example 
Java :: stream filter java 8 
Java :: how to find mongo java driver version 
Java :: java check array for duplicates 
Java :: java arraylist initialize with 0 
Java :: custom dialog in android 
Java :: how to remove last latter in word in java 
Java :: what is ioexception in java 
Java :: generate hash in java 
Java :: encryption 
Java :: java decler variabel 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =