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());
}
}
}
Also in Java:
- vector in java
- Kotlin is like java
- javafx fill tableview with data
- java how to serialize a file into a local server
- java how to program
- java exit
- processing sound library
- java polymorphism
- bukkit java get max players
- how to install java runtime environment on centos 7
- java how to get all threads
- checking if a given integer is a prime number java
- java map example
- get value textfield java
- binary numbers java
- java hashmap put
- bukkit java set leather armor color from hex
- system.arraycopy java
- difference between java and javax
- count the number of words in a string java
- java iterate over a string
- java remove duplicates
- how to create a java jframe
- java output length of each line in a text document