Class XMLSerializer


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

      • XMLSerializer

        public XMLSerializer​(java.io.OutputStream pOutput,
                             java.lang.String pEncoding)
    • 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 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​(java.io.PrintWriter pOut)
      • writeProcessingInstruction

        private void writeProcessingInstruction​(java.io.PrintWriter pOut,
                                                org.w3c.dom.ProcessingInstruction pNode)
      • writeCData

        private void writeCData​(java.io.PrintWriter pOut,
                                org.w3c.dom.Node pNode)
      • 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)
      • 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.IOException
        org.xml.sax.SAXException