Package com.twelvemonkeys.xml
Class XMLSerializer
- java.lang.Object
-
- com.twelvemonkeys.xml.XMLSerializer
-
public class XMLSerializer extends java.lang.ObjectXMLSerializer- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/xml/XMLSerializer.java#1 $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classXMLSerializer.SerializationContext
-
Field Summary
Fields Modifier and Type Field Description private XMLSerializer.SerializationContextcontextprivate java.nio.charset.Charsetencodingprivate java.io.OutputStreamoutput
-
Constructor Summary
Constructors Constructor Description XMLSerializer(java.io.OutputStream pOutput, java.lang.String pEncoding)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static intappendAndEscape(java.lang.String pString, int pStart, int pEnd, java.lang.StringBuilder pBuilder, java.lang.String pEntity)XMLSerializerindentation(java.lang.String pIndent)private static voidindentToLevel(java.io.PrintWriter pOut, XMLSerializer.SerializationContext pContext)static voidmain(java.lang.String[] pArgs)private static java.lang.StringmaybeEscapeAttributeValue(java.lang.String pValue)(package private) static java.lang.StringmaybeEscapeElementValue(java.lang.String pValue)Returns an escaped version of the input string.private static intneedsEscapeAttribute(java.lang.String pString)Returns an the first index from the input string that should be escaped if escaping is needed, otherwise-1.private static intneedsEscapeElement(java.lang.String pString)Returns an the first index from the input string that should be escaped if escaping is needed, otherwise-1.voidserialize(org.w3c.dom.Document pDocument)Serializes the entire document, along with the XML declaration (<?xml version="1.0" encoding="..."?>).voidserialize(org.w3c.dom.Node pRootNode, boolean pWriteXMLDeclaration)Serializes the entire sub tree starting atpRootNode, along with an optional XML declaration (<?xml version="1.0" encoding="..."?>).XMLSerializerstripComments(boolean pStrip)private static voidupdatePreserveSpace(org.w3c.dom.Node pNode, XMLSerializer.SerializationContext pContext)private static java.lang.StringvalidateCDataValue(java.lang.String pValue)private static java.lang.StringvalidateCommentValue(java.lang.String pValue)private voidwriteCData(java.io.PrintWriter pOut, org.w3c.dom.Node pNode)private voidwriteComment(java.io.PrintWriter pOut, org.w3c.dom.Node pNode, XMLSerializer.SerializationContext pContext)private voidwriteDoctype(java.io.PrintWriter pOut, org.w3c.dom.DocumentType pDoctype)private voidwriteDocument(java.io.PrintWriter pOut, org.w3c.dom.Node pNode, XMLSerializer.SerializationContext pContext)private voidwriteElement(java.io.PrintWriter pOut, org.w3c.dom.Element pNode, XMLSerializer.SerializationContext pContext)private voidwriteNodeRecursive(java.io.PrintWriter pOut, org.w3c.dom.Node pNode, XMLSerializer.SerializationContext pContext)private voidwriteProcessingInstruction(java.io.PrintWriter pOut, org.w3c.dom.ProcessingInstruction pNode)private voidwriteText(java.io.PrintWriter pOut, org.w3c.dom.Node pNode, XMLSerializer.SerializationContext pContext)private voidwriteXML(java.io.PrintWriter pOut, org.w3c.dom.Node pDocument, XMLSerializer.SerializationContext pContext)private voidwriteXMLDeclaration(java.io.PrintWriter pOut)
-
-
-
Field Detail
-
output
private final java.io.OutputStream output
-
encoding
private final java.nio.charset.Charset encoding
-
context
private final XMLSerializer.SerializationContext context
-
-
Method Detail
-
indentation
public final XMLSerializer indentation(java.lang.String pIndent)
-
stripComments
public final XMLSerializer stripComments(boolean pStrip)
-
serialize
public void serialize(org.w3c.dom.Document pDocument)
Serializes the entire document, along with the XML declaration (<?xml version="1.0" encoding="..."?>).- Parameters:
pDocument- the document to serialize.
-
serialize
public void serialize(org.w3c.dom.Node pRootNode, boolean pWriteXMLDeclaration)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-trueif the XML declaration should be included, otherwisefalse.
-
writeXMLDeclaration
private void writeXMLDeclaration(java.io.PrintWriter pOut)
-
writeXML
private void writeXML(java.io.PrintWriter pOut, org.w3c.dom.Node pDocument, XMLSerializer.SerializationContext pContext)
-
writeNodeRecursive
private void writeNodeRecursive(java.io.PrintWriter pOut, org.w3c.dom.Node pNode, XMLSerializer.SerializationContext pContext)
-
writeProcessingInstruction
private void writeProcessingInstruction(java.io.PrintWriter pOut, org.w3c.dom.ProcessingInstruction pNode)
-
writeText
private void writeText(java.io.PrintWriter pOut, org.w3c.dom.Node pNode, XMLSerializer.SerializationContext pContext)
-
writeCData
private void writeCData(java.io.PrintWriter pOut, org.w3c.dom.Node pNode)
-
updatePreserveSpace
private static void updatePreserveSpace(org.w3c.dom.Node pNode, XMLSerializer.SerializationContext pContext)
-
indentToLevel
private static void indentToLevel(java.io.PrintWriter pOut, XMLSerializer.SerializationContext pContext)
-
writeComment
private void writeComment(java.io.PrintWriter pOut, org.w3c.dom.Node pNode, XMLSerializer.SerializationContext pContext)
-
maybeEscapeElementValue
static java.lang.String maybeEscapeElementValue(java.lang.String pValue)
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(java.lang.String pString, int pStart, int pEnd, java.lang.StringBuilder pBuilder, java.lang.String pEntity)
-
needsEscapeElement
private static int needsEscapeElement(java.lang.String pString)
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
private static java.lang.String maybeEscapeAttributeValue(java.lang.String pValue)
-
needsEscapeAttribute
private static int needsEscapeAttribute(java.lang.String pString)
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
private static java.lang.String validateCDataValue(java.lang.String pValue)
-
validateCommentValue
private static java.lang.String validateCommentValue(java.lang.String pValue)
-
writeDocument
private void writeDocument(java.io.PrintWriter pOut, org.w3c.dom.Node pNode, XMLSerializer.SerializationContext pContext)
-
writeElement
private void writeElement(java.io.PrintWriter pOut, org.w3c.dom.Element pNode, XMLSerializer.SerializationContext pContext)
-
writeDoctype
private void writeDoctype(java.io.PrintWriter pOut, org.w3c.dom.DocumentType pDoctype)
-
main
public static void main(java.lang.String[] pArgs) throws java.io.IOException, org.xml.sax.SAXException- Throws:
java.io.IOExceptionorg.xml.sax.SAXException
-
-