XML technologies / XML / XML in a Nutshell / The Document Object Model (DOM) / Documents with DOM: parsing
(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)
Although DOM Level 2 does not specify a proper interface for parsing a document, most implementations provide a simple interface for this purpose. It accepts a reference to an XML file, a stream or a URI. Once this interface has successfully parsed and validated a document (validation applies only to validating parsers), it usually provides a mechanism for obtaining a reference to an instance of the Document interface for the parsed document. The following code fragment shows how to parse a document with the Apache Xerces XML DOM parser:
// Erzeuge einen neuen Parser
DOMParser dp = new DOMParser( );
// Parse das Dokument, und hole das DOM-Interface Document
dp.parse("http://www.w3.org/TR/2000/REC-xml-20001006.xml");
Document doc = dp.getDocument( );Note: DOM Level 3 introduces a standard mechanism for loading XML documents and reconstructing (saving) XML from DOM trees. JAXP also provides a standardized approach to these processes in Java, although the approaches of JAXP and DOM Level 3 differ.
Copyright © 2005 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from the book "XML in a Nutshell" is subject to the same conditions as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de
back to top