Class XMLFactory


  • public final class XMLFactory
    extends Object
    Utility class for creating XML DOM documents.
    Author:
    Philip Helger
    • Field Detail

      • DEFAULT_DOM_NAMESPACE_AWARE

        public static final boolean DEFAULT_DOM_NAMESPACE_AWARE
        DocumentBuilderFactory is by default namespace aware
        See Also:
        Constant Field Values
      • DEFAULT_DOM_VALIDATING

        public static final boolean DEFAULT_DOM_VALIDATING
        DocumentBuilderFactory is by default not DTD validating
        See Also:
        Constant Field Values
      • DEFAULT_DOM_IGNORING_ELEMENT_CONTENT_WHITESPACE

        public static final boolean DEFAULT_DOM_IGNORING_ELEMENT_CONTENT_WHITESPACE
        DocumentBuilderFactory is by default not ignoring element content whitespace
        See Also:
        Constant Field Values
      • DEFAULT_DOM_EXPAND_ENTITY_REFERENCES

        public static final boolean DEFAULT_DOM_EXPAND_ENTITY_REFERENCES
        DocumentBuilderFactory is by default entity reference expanding
        See Also:
        Constant Field Values
      • DEFAULT_DOM_IGNORING_COMMENTS

        public static final boolean DEFAULT_DOM_IGNORING_COMMENTS
        DocumentBuilderFactory is by default ignoring comments
        See Also:
        Constant Field Values
      • DEFAULT_DOM_COALESCING

        public static final boolean DEFAULT_DOM_COALESCING
        DocumentBuilderFactory is by default coalescing
        See Also:
        Constant Field Values
      • DEFAULT_DOM_XINCLUDE_AWARE

        public static final boolean DEFAULT_DOM_XINCLUDE_AWARE
        DocumentBuilderFactory is by default not XInclude aware
        See Also:
        Constant Field Values
    • Method Detail

      • reinitialize

        public static void reinitialize()
        Reinitialize the document builder factory. This may be necessary if the system properties change!
      • createDocumentBuilderFactory

        @Nonnull
        public static DocumentBuilderFactory createDocumentBuilderFactory​(@Nonnull
                                                                          Schema aSchema)
        Create a new DocumentBuilderFactory for the specified schema, with the following settings: coalescing, comment ignoring and namespace aware.
        Parameters:
        aSchema - The schema to use. May not be null.
        Returns:
        Never null.
      • getDocumentBuilderFactory

        @Nonnull
        public static DocumentBuilderFactory getDocumentBuilderFactory()
        Returns:
        The default document builder factory that is not schema specific. Never null.
      • getDocumentBuilder

        @Nonnull
        public static DocumentBuilder getDocumentBuilder()
        Returns:
        The default document builder that is not schema specific. Never null.
      • getDOMImplementation

        @Nonnull
        public static DOMImplementation getDOMImplementation()
        Returns:
        The DOM implementation of the default document builder. Never null.
      • createDocumentBuilder

        @Nonnull
        public static DocumentBuilder createDocumentBuilder()
        Create a document builder without a certain schema, using the default DocumentBuilderFactory.
        Returns:
        The created document builder. Never null.
      • createDocumentBuilder

        @Nonnull
        public static DocumentBuilder createDocumentBuilder​(@Nonnull
                                                            Schema aSchema)
        Create a document builder for a certain schema.
        Parameters:
        aSchema - The schema to use. May not be null.
        Returns:
        The created document builder. Never null.
      • createDocumentBuilder

        @Nonnull
        public static DocumentBuilder createDocumentBuilder​(@Nonnull
                                                            DocumentBuilderFactory aDocBuilderFactory)
        Create a document builder without a certain schema, using the passed DocumentBuilderFactory.
        Parameters:
        aDocBuilderFactory - The document builder factory to be used. May not be null.
        Returns:
        The created document builder. Never null.
        Throws:
        com.helger.commons.exception.InitializationException - In case some DOM initialization goes wrong
      • newDocument

        @Nonnull
        public static Document newDocument()
        Create a new XML document without document type using version EXMLVersion.XML_10. The default document builder is used.
        Returns:
        The created document. Never null.
      • newDocument

        @Nonnull
        public static Document newDocument​(@Nonnull
                                           DocumentBuilder aDocBuilder)
        Create a new XML document without document type using version EXMLVersion.XML_10. A custom document builder is used.
        Parameters:
        aDocBuilder - The document builder to use. May not be null.
        Returns:
        The created document. Never null.
      • newDocument

        @Nonnull
        public static Document newDocument​(@Nullable
                                           EXMLVersion eVersion)
        Create a new XML document without document type using the default document builder.
        Parameters:
        eVersion - The XML version to use. If null is passed, EXMLVersion.XML_10 will be used.
        Returns:
        The created document. Never null.
      • newDocument

        @Nonnull
        public static Document newDocument​(@Nonnull
                                           DocumentBuilder aDocBuilder,
                                           @Nullable
                                           EXMLVersion eVersion)
        Create a new XML document without document type using a custom document builder.
        Parameters:
        aDocBuilder - The document builder to use. May not be null.
        eVersion - The XML version to use. If null is passed, EXMLVersion.XML_10 will be used.
        Returns:
        The created document. Never null.
      • newDocument

        @Nonnull
        public static Document newDocument​(@Nonnull
                                           String sQualifiedName,
                                           @Nullable
                                           String sPublicId,
                                           @Nullable
                                           String sSystemId)
        Create a new document with a document type using version EXMLVersion.XML_10.
        Parameters:
        sQualifiedName - The qualified name to use.
        sPublicId - The public ID of the document type.
        sSystemId - The system ID of the document type.
        Returns:
        The created document. Never null.
      • newDocument

        @Nonnull
        public static Document newDocument​(@Nullable
                                           EXMLVersion eVersion,
                                           @Nonnull
                                           String sQualifiedName,
                                           @Nullable
                                           String sPublicId,
                                           @Nullable
                                           String sSystemId)
        Create a new document with a document type using the default document builder.
        Parameters:
        eVersion - The XML version to use. If null is passed, EXMLVersion.XML_10 will be used.
        sQualifiedName - The qualified name to use.
        sPublicId - The public ID of the document type.
        sSystemId - The system ID of the document type.
        Returns:
        The created document. Never null.
      • newDocument

        @Nonnull
        public static Document newDocument​(@Nonnull
                                           DocumentBuilder aDocBuilder,
                                           @Nullable
                                           EXMLVersion eVersion,
                                           @Nonnull
                                           String sQualifiedName,
                                           @Nullable
                                           String sPublicId,
                                           @Nullable
                                           String sSystemId)
        Create a new document with a document type using a custom document builder.
        Parameters:
        aDocBuilder - the document builder to be used. May not be null.
        eVersion - The XML version to use. If null is passed, EXMLVersion.XML_10 will be used.
        sQualifiedName - The qualified name to use.
        sPublicId - The public ID of the document type.
        sSystemId - The system ID of the document type.
        Returns:
        The created document. Never null.