Class XMLSerializer

java.lang.Object
com.twelvemonkeys.xml.XMLSerializer

public class XMLSerializer extends Object
XMLSerializer
Version:
$Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/xml/XMLSerializer.java#1 $
  • Field Details

  • Constructor Details

  • Method Details

    • indentation

      public final XMLSerializer indentation(String pIndent)
    • stripComments

      public final XMLSerializer stripComments(boolean pStrip)
    • serialize

      public void serialize(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(Node pRootNode, boolean pWriteXMLDeclaration)
      Serializes the entire sub tree starting at pRootNode, 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, otherwise false.
    • writeXMLDeclaration

      private void writeXMLDeclaration(PrintWriter pOut)
    • writeXML

      private void writeXML(PrintWriter pOut, Node pDocument, XMLSerializer.SerializationContext pContext)
    • writeNodeRecursive

      private void writeNodeRecursive(PrintWriter pOut, Node pNode, XMLSerializer.SerializationContext pContext)
    • writeProcessingInstruction

      private void writeProcessingInstruction(PrintWriter pOut, ProcessingInstruction pNode)
    • writeText

      private void writeText(PrintWriter pOut, Node pNode, XMLSerializer.SerializationContext pContext)
    • writeCData

      private void writeCData(PrintWriter pOut, Node pNode)
    • updatePreserveSpace

      private static void updatePreserveSpace(Node pNode, XMLSerializer.SerializationContext pContext)
    • indentToLevel

      private static void indentToLevel(PrintWriter pOut, XMLSerializer.SerializationContext pContext)
    • writeComment

      private void writeComment(PrintWriter pOut, Node pNode, XMLSerializer.SerializationContext pContext)
    • maybeEscapeElementValue

      static String maybeEscapeElementValue(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(String pString, int pStart, int pEnd, StringBuilder pBuilder, String pEntity)
    • needsEscapeElement

      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.
      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 String maybeEscapeAttributeValue(String pValue)
    • needsEscapeAttribute

      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.
      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 String validateCDataValue(String pValue)
    • validateCommentValue

      private static String validateCommentValue(String pValue)
    • writeDocument

      private void writeDocument(PrintWriter pOut, Node pNode, XMLSerializer.SerializationContext pContext)
    • writeElement

      private void writeElement(PrintWriter pOut, Element pNode, XMLSerializer.SerializationContext pContext)
    • writeDoctype

      private void writeDoctype(PrintWriter pOut, DocumentType pDoctype)
    • main

      public static void main(String[] pArgs) throws IOException, SAXException
      Throws:
      IOException
      SAXException