Package com.helger.xml.serialize.write
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 Summary
Fields Modifier and Type Field Description static NamespaceContextDEFAULT_NAMESPACE_CTXBy default no XML namespace map is presentstatic EXMLVersionDEFAULT_XML_VERSIONThe default XML version to be used
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]getNodeAsBytes(Node aNode)Convert the passed micro node to an XML byte array usingXMLWriterSettings.DEFAULT_XML_SETTINGS.static byte[]getNodeAsBytes(Node aNode, IXMLWriterSettings aSettings)Convert the passed DOM node to an XML byte array using the provided XML writer settings.static StringgetNodeAsString(Node aNode)Convert the passed DOM node to an XML string usingXMLWriterSettings.DEFAULT_XML_SETTINGS.static StringgetNodeAsString(Node aNode, IXMLWriterSettings aSettings)Convert the passed DOM node to an XML string using the provided XML writer settings.static com.helger.commons.state.ESuccesswriteToStream(Node aNode, OutputStream aOS)Write a node to anOutputStreamusing the default settings.static com.helger.commons.state.ESuccesswriteToStream(Node aNode, OutputStream aOS, IXMLWriterSettings aSettings)Write a node to anOutputStreamusing custom settings.static com.helger.commons.state.ESuccesswriteToWriter(Node aNode, Writer aWriter)Write a node to aWriterusing the default settings.static com.helger.commons.state.ESuccesswriteToWriter(Node aNode, Writer aWriter, IXMLWriterSettings aSettings)Write a node to aWriterusing the default settings.
-
-
-
Field Detail
-
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 Detail
-
writeToStream
@Nonnull public static com.helger.commons.state.ESuccess writeToStream(@Nonnull Node aNode, @Nonnull @WillClose OutputStream aOS)
Write a node to anOutputStreamusing the default settings.- Parameters:
aNode- The node to be serialized. May be any kind of node (incl. documents). May not benull.aOS- TheOutputStreamto write to. May not benull. TheOutputStreamis 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 anOutputStreamusing custom settings.- Parameters:
aNode- The node to be serialized. May be any kind of node (incl. documents). May not benull.aOS- TheOutputStreamto write to. May not benull. TheOutputStreamis closed anyway directly after the operation finishes (on success and on error).aSettings- The serialization settings to be used. May not benull.- Returns:
ESuccess
-
writeToWriter
@Nonnull public static com.helger.commons.state.ESuccess writeToWriter(@Nonnull Node aNode, @Nonnull @WillClose Writer aWriter)
Write a node to aWriterusing the default settings.
-
writeToWriter
@Nonnull public static com.helger.commons.state.ESuccess writeToWriter(@Nonnull Node aNode, @Nonnull @WillClose Writer aWriter, @Nonnull IXMLWriterSettings aSettings)
Write a node to aWriterusing the default settings.- Parameters:
aNode- The node to be serialized. May be any kind of node (incl. documents). May not benull.aWriter- TheWriterto write to. May not benull. TheWriteris closed anyway directly after the operation finishes (on success and on error).aSettings- The serialization settings to be used. May not benull.- 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 benull.aSettings- The XML writer settings to be used. May not benull.- 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 usingXMLWriterSettings.DEFAULT_XML_SETTINGS. This is a specialized version ofgetNodeAsString(Node, IXMLWriterSettings).- Parameters:
aNode- The node to be converted to a string. May not benull.- 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 benull.aSettings- The XML writer settings to be used. May not benull.- 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 usingXMLWriterSettings.DEFAULT_XML_SETTINGS. This is a specialized version ofgetNodeAsBytes(Node, IXMLWriterSettings).- Parameters:
aNode- The node to be converted to a byte array. May not benull.- Returns:
- The byte array representation of the passed node.
- Since:
- 8.6.3
-
-