O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing XML with DOM

File file = new File("document.xml");
											DocumentBuilderFactory f =
											DocumentBuilderFactory.newInstance();
											DocumentBuilder p = f.newDocumentBuilder();
											Document doc = p.parse(file);

The DocumentBuilderFactory, DocumentBuilder, and Document classes are the three classes that we use to kick off the parsing of an XML document using a DOM parser. We perform the parsing with the DocumentBuilder class. The DocumentBuilder class defines the API to obtain DOM Document instances from an XML document. The DocumentBuilder class can parse XML from a variety of input sources, including InputStreams, Files, URLs, and SAXInputSources. In this phrase, we parse the XML from a File input source. The parse() method of the DocumentBuilder class parses ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required