Java examples for XML:DOM
Parse XML File using DOM Parser
//package com.java2s; import java.io.File; 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 { init();/*w w w . jav a 2 s.co m*/ } private static String xmlFilePath; public static Document document; /** * Die init() Methode sorgt dafuer das das XML File geladen wird. * @throws Exception */ public static void init() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse(new File(getXmlFilePath())); } /** * Die getXmlFilePath() Methode gibt den xmlFilePath zurueck. * @return xmlFilePath */ public static String getXmlFilePath() { return xmlFilePath; } }