We would like to know how to read Xml attributes.
import java.io.File; /*from ww w . ja va 2s. c o m*/ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; public class Main { public static void main(String argv[]) throws Exception { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(new File("data.xml")); doc.getDocumentElement().normalize(); System.out.println("City: " + doc.getDocumentElement().getChildNodes().item(0) .getFirstChild().getChildNodes().item(0).getAttributes() .getNamedItem("data").getNodeValue()); System.out.println("Postal Code: " + doc.getDocumentElement().getChildNodes().item(0) .getFirstChild().getChildNodes().item(1).getAttributes() .getNamedItem("data").getNodeValue()); System.out.println("Date: " + doc.getDocumentElement().getChildNodes().item(0) .getFirstChild().getChildNodes().item(4).getAttributes() .getNamedItem("data").getNodeValue()); } }