I'm new to XML. I'm studying the javax.xml.parsers package. This package is 4 classes. Interested in DocumentBuilderFactory and DocumentBuilder. (SAX is not touching).

  1. question on the factory class. As I understand it, a factory can load a third-party class and use its implementation (method newInstance (String factoryClassName, ClassLoader classLoader)). And what does the newInstance () method do that without parameters? loads the default implementation of this factory?
  2. question on DocumentBuilder. Depending on the implementation, the factory returns this DocumentBuilder. What kind of object is this parser object itself? If so who is it written by?
  3. What is the DOMParser class? I found in one book that the author works directly with him, without any factories. And besides, this DOMPaser is somehow strange - you cannot create a new document with it.
  4. What is JAXP? Is it a library for working with XML in java?

    1 answer 1

    And what does the newInstance () method do that without parameters?

    If the question arises as to what the method does, it is logical to start by reading the documentation.

    The following algorithm is used to select the DocumentBuilderFactory implementation:

    1. The class name is taken from the value of the javax.xml.parsers.DocumentBuilderFactory system property.
    2. If it is not specified, the value of the javax.xml.parsers.DocumentBuilderFactory property is checked in the properties file ib/jaxp.properties
    3. If the value is not specified there, all jar-nicks included in the classpath are checked for the presence of the META-INF / services / javax.xml.parsers.DocumentBuilderFactory file.
    4. If this does not help, the default implementation is used.

    What kind of object is this parser object itself? If so who is it written by?

    Yes. Who it is written for depends on which implementation you use (see above). Obviously, the default implementation is written by Sun.

    DOMPaser is somehow strange - you cannot create a new document with it.

    That's why it is a parser to parse an existing doc.

    What is JAXP? Is it a library for working with XML in java?

    Simplified - yes.

    This is actually an API specification for handling XML that can be implemented by third-party developers as libraries. As usually happens in such cases, there is also a standard implementation from Sun.

    • 1) strange - after all DocumentBuilder and DOMParser are parsers, however DOMParser cannot create a new Document. 2) and it is also very strange that the DOMParser is not the heir of DocumentBuilder. :( ZY opening the DocumentBuilder implementation found that DocumentBuilder delegates to DOMParser. Probably there are no more questions. Thank you - arg