XML Parsing
Document
object that
represents our XML file. Since Document
is an
interface we must use a factory.import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.io.File; import org.w3c.dom.Document; public class OrderProcessor { public static void main (String args[]) { File docFile = new File("orders.xml"); Document doc = null; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); //A document builder builds specific documents. DocumentBuilder db = dbf.newDocumentBuilder(); //This call parses the file and creates the Document in memory. doc = db.parse(docFile); } catch (Exception e) { System.out.print("Problem parsing the file."); } } }
8 of 16