Parse an XML File with DOM


import java.io.File;

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

import org.w3c.dom.Document;

public class MainClass {

  public static void main(String[] args) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = null;
    db = dbf.newDocumentBuilder();
    Document doc = db.parse(new File("games.xml"));
  }
}
Home 
  Java Book 
    Runnable examples  

XML DOM:
  1. Creating XML Element and add to Document
  2. Create and add Attribute to an Element
  3. Parse an XML File with DOM
  4. Parse an XML file with custom error handler
  5. Parse an XML string with DOM and StringReader.
  6. Visit all nodes from DOM
  7. Visit all nodes from DOM and output node type