Package com.twelvemonkeys.xml
Class XMLSerializer
java.lang.Object
com.twelvemonkeys.xml.XMLSerializer
XMLSerializer
- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/xml/XMLSerializer.java#1 $
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final XMLSerializer.SerializationContext
private final Charset
private final OutputStream
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static int
appendAndEscape
(String pString, int pStart, int pEnd, StringBuilder pBuilder, String pEntity) final XMLSerializer
indentation
(String pIndent) private static void
indentToLevel
(PrintWriter pOut, XMLSerializer.SerializationContext pContext) static void
private static String
maybeEscapeAttributeValue
(String pValue) (package private) static String
maybeEscapeElementValue
(String pValue) Returns an escaped version of the input string.private static int
needsEscapeAttribute
(String pString) Returns an the first index from the input string that should be escaped if escaping is needed, otherwise-1
.private static int
needsEscapeElement
(String pString) Returns an the first index from the input string that should be escaped if escaping is needed, otherwise-1
.void
Serializes the entire document, along with the XML declaration (<?xml version="1.0" encoding="..."?>
).void
Serializes the entire sub tree starting atpRootNode
, along with an optional XML declaration (<?xml version="1.0" encoding="..."?>
).final XMLSerializer
stripComments
(boolean pStrip) private static void
updatePreserveSpace
(Node pNode, XMLSerializer.SerializationContext pContext) private static String
validateCDataValue
(String pValue) private static String
validateCommentValue
(String pValue) private void
writeCData
(PrintWriter pOut, Node pNode) private void
writeComment
(PrintWriter pOut, Node pNode, XMLSerializer.SerializationContext pContext) private void
writeDoctype
(PrintWriter pOut, DocumentType pDoctype) private void
writeDocument
(PrintWriter pOut, Node pNode, XMLSerializer.SerializationContext pContext) private void
writeElement
(PrintWriter pOut, Element pNode, XMLSerializer.SerializationContext pContext) private void
writeNodeRecursive
(PrintWriter pOut, Node pNode, XMLSerializer.SerializationContext pContext) private void
writeProcessingInstruction
(PrintWriter pOut, ProcessingInstruction pNode) private void
writeText
(PrintWriter pOut, Node pNode, XMLSerializer.SerializationContext pContext) private void
writeXML
(PrintWriter pOut, Node pDocument, XMLSerializer.SerializationContext pContext) private void
-
Field Details
-
output
-
encoding
-
context
-
-
Constructor Details
-
XMLSerializer
-
-
Method Details
-
indentation
-
stripComments
-
serialize
Serializes the entire document, along with the XML declaration (<?xml version="1.0" encoding="..."?>
).- Parameters:
pDocument
- the document to serialize.
-
serialize
Serializes the entire sub tree starting atpRootNode
, along with an optional XML declaration (<?xml version="1.0" encoding="..."?>
).- Parameters:
pRootNode
- the root node to serialize.pWriteXMLDeclaration
-true
if the XML declaration should be included, otherwisefalse
.
-
writeXMLDeclaration
-
writeXML
private void writeXML(PrintWriter pOut, Node pDocument, XMLSerializer.SerializationContext pContext) -
writeNodeRecursive
private void writeNodeRecursive(PrintWriter pOut, Node pNode, XMLSerializer.SerializationContext pContext) -
writeProcessingInstruction
-
writeText
-
writeCData
-
updatePreserveSpace
-
indentToLevel
-
writeComment
private void writeComment(PrintWriter pOut, Node pNode, XMLSerializer.SerializationContext pContext) -
maybeEscapeElementValue
Returns an escaped version of the input string. The string is guaranteed to not contain illegal XML characters (&<>
). If no escaping is needed, the input string is returned as is.- Parameters:
pValue
- the input string that might need escaping.- Returns:
- an escaped version of the input string.
-
appendAndEscape
private static int appendAndEscape(String pString, int pStart, int pEnd, StringBuilder pBuilder, String pEntity) -
needsEscapeElement
Returns an the first index from the input string that should be escaped if escaping is needed, otherwise-1
.- Parameters:
pString
- the input string that might need escaping.- Returns:
- the first index from the input string that should be escaped,
or
-1
.
-
maybeEscapeAttributeValue
-
needsEscapeAttribute
Returns an the first index from the input string that should be escaped if escaping is needed, otherwise-1
.- Parameters:
pString
- the input string that might need escaping.- Returns:
- the first index from the input string that should be escaped,
or
-1
.
-
validateCDataValue
-
validateCommentValue
-
writeDocument
private void writeDocument(PrintWriter pOut, Node pNode, XMLSerializer.SerializationContext pContext) -
writeElement
private void writeElement(PrintWriter pOut, Element pNode, XMLSerializer.SerializationContext pContext) -
writeDoctype
-
main
- Throws:
IOException
SAXException
-