Class XMLWriter

java.lang.Object
com.helger.xml.serialize.write.XMLWriter

@Immutable public final class XMLWriter extends Object
This is a helper class to serialize DOM nodes to a String.
Author:
Philip Helger
  • Field Details

    • DEFAULT_XML_VERSION

      public static final EXMLVersion DEFAULT_XML_VERSION
      The default XML version to be used
    • DEFAULT_NAMESPACE_CTX

      public static final NamespaceContext DEFAULT_NAMESPACE_CTX
      By default no XML namespace map is present
  • Method Details

    • writeToStream

      @Nonnull public static com.helger.commons.state.ESuccess writeToStream(@Nonnull Node aNode, @Nonnull @WillClose OutputStream aOS)
      Write a node to an OutputStream using the default settings.
      Parameters:
      aNode - The node to be serialized. May be any kind of node (incl. documents). May not be null.
      aOS - The OutputStream to write to. May not be null. The OutputStream is closed anyway directly after the operation finishes (on success and on error).
      Returns:
      ESuccess
    • writeToStream

      @Nonnull public static com.helger.commons.state.ESuccess writeToStream(@Nonnull Node aNode, @Nonnull @WillClose OutputStream aOS, @Nonnull IXMLWriterSettings aSettings)
      Write a node to an OutputStream using custom settings.
      Parameters:
      aNode - The node to be serialized. May be any kind of node (incl. documents). May not be null.
      aOS - The OutputStream to write to. May not be null. The OutputStream is closed anyway directly after the operation finishes (on success and on error).
      aSettings - The serialization settings to be used. May not be null.
      Returns:
      ESuccess
    • writeToWriter

      @Nonnull public static com.helger.commons.state.ESuccess writeToWriter(@Nonnull Node aNode, @Nonnull @WillClose Writer aWriter)
      Write a node to a Writer using the default settings.
      Parameters:
      aNode - The node to be serialized. May be any kind of node (incl. documents). May not be null.
      aWriter - The Writer to write to. May not be null. The Writer is closed anyway directly after the operation finishes (on success and on error).
      Returns:
      ESuccess
    • writeToWriter

      @Nonnull public static com.helger.commons.state.ESuccess writeToWriter(@Nonnull Node aNode, @Nonnull @WillClose Writer aWriter, @Nonnull IXMLWriterSettings aSettings)
      Write a node to a Writer using the default settings.
      Parameters:
      aNode - The node to be serialized. May be any kind of node (incl. documents). May not be null.
      aWriter - The Writer to write to. May not be null. The Writer is closed anyway directly after the operation finishes (on success and on error).
      aSettings - The serialization settings to be used. May not be null.
      Returns:
      ESuccess
    • getNodeAsString

      @Nullable public static String getNodeAsString(@Nonnull Node aNode, @Nonnull IXMLWriterSettings aSettings)
      Convert the passed DOM node to an XML string using the provided XML writer settings.
      Parameters:
      aNode - The node to be converted to a string. May not be null .
      aSettings - The XML writer settings to be used. May not be null.
      Returns:
      The string representation of the passed node.
      Since:
      8.6.3
    • getNodeAsString

      @Nullable public static String getNodeAsString(@Nonnull Node aNode)
      Convert the passed DOM node to an XML string using XMLWriterSettings.DEFAULT_XML_SETTINGS. This is a specialized version of getNodeAsString(Node, IXMLWriterSettings).
      Parameters:
      aNode - The node to be converted to a string. May not be null .
      Returns:
      The string representation of the passed node.
      Since:
      8.6.3
    • getNodeAsBytes

      @Nullable public static byte[] getNodeAsBytes(@Nonnull Node aNode, @Nonnull IXMLWriterSettings aSettings)
      Convert the passed DOM node to an XML byte array using the provided XML writer settings.
      Parameters:
      aNode - The node to be converted to a byte array. May not be null.
      aSettings - The XML writer settings to be used. May not be null.
      Returns:
      The byte array representation of the passed node.
      Since:
      8.6.3
    • getNodeAsBytes

      @Nullable public static byte[] getNodeAsBytes(@Nonnull Node aNode)
      Convert the passed micro node to an XML byte array using XMLWriterSettings.DEFAULT_XML_SETTINGS. This is a specialized version of getNodeAsBytes(Node, IXMLWriterSettings).
      Parameters:
      aNode - The node to be converted to a byte array. May not be null .
      Returns:
      The byte array representation of the passed node.
      Since:
      8.6.3