I can't find any information on org.w3c.dom.ls.LSParser
. I know it is an interface but there is an on only way to get a concrete object afaik.
DOMImplementationLS factory = (DOMImplementationLS) myXMLDocument.getImplementation();
LSParser parser = factory.createLSParser(DOMImplementationLS.MODE_ASYNCHRONOUS, null);
How is LSParser different from javax.xml.parsers.DocumentBuilder
(or SAXParser)
Class DocumentBuilder. Defines the API to obtain DOM Document instances from an XML document. Using this class, an application programmer can obtain a Document from XML. An instance of this class can be obtained from the DocumentBuilderFactory.
The Javax.xml.parsers.DocumentBuilderFactory.setNamespaceAware(boolean awareness) method specifies that the parsers created by this factory will provide support for XML namespaces. By default the value of this is set to false.
setExpandEntityReferences(boolean expandEntityRef) Specifies that the parser produced by this code will expand entity reference nodes. abstract void. setFeature(String name, boolean value) Set a feature for this DocumentBuilderFactory and DocumentBuilder s created by this factory.
First, a SAXParser is different from the javax.xml.parsers.DocumentBuilder and LSParser, in that it streams through the XML, instead of building a Document Object Model (DOM).
That leaves us with explaining javax.xml.parsers.DocumentBuilder and LSParser. The DOM spec has levels to define the structure and behavior of the DOM. There are three levels. (1, 2, and 3). LSParser stands for "Load and Save Parser". This Parser provides support for DOM Level 3. It implements the behavior defined here - https://www.w3.org/TR/DOM-Level-3-LS/load-save.html . Since LSParser supports the DOM Level 3 standard, it allows event handling (when DOM is loaded), saving and filtering. Note that this is a spec, so it can be implemented in any language.
In contrast, javax.xml.parsers.DocumentBuilder is a Java based API (JAXP). It is a project, not a spec.
LSParser spec has been influenced by both the JAXP and SAX projects. It just standardized the parsing of XML and using the DOM.
References: https://www.amazon.com/Processing-XML-documents-Oracle-JDeveloper/dp/1847196667 (Refer Chapter 7 - relevant to this topic).
https://www.w3.org/TR/DOM-Level-3-LS/load-save.html (this is the full spec).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With