Loading an XML document
In this section, we shall load the example XML document catalog.xml
using the DOM 3 Load and Save API. The LSParser
interface in the org.w3c.dom.ls
package is used to load an XML document, parse an XML document, and obtain a Document
object. The document loaded by LSParser
may also be validated with an XML Schema. The following code is the standard way to retrieve a DOM implementation, which can then be used to parse an XML document. Most of the code is simply used to initialize registries and properties so as to extract the final parser. First, we need to import the DOM 3.0 LS package.
import org. w3c.dom.ls.*;
Creating the LSParser
The DOMImplementationLS
interface is used to create Load and Save objects, including the LSParser
object. Create a DOMImplementationLS
object by creating an instance of the XMLDOMImplementation
class, which implements the DOMImplementationLS
interface.
DOMImplementationLS domImpl = new XMLDOMImplementation();
The DOMImplementationLS...