org.apache.xml.serialize
public class XMLSerializer extends BaseMarkupSerializer
If an output stream is used, the encoding is taken from the output format (defaults to UTF-8). If a writer is used, make sure the writer uses the same encoding (if applies) as specified in the output format.
The serializer supports both DOM and SAX. SAX serializing is done by firing SAX events and using the serializer as a document handler. DOM serializing is done by calling {@link #serialize(Document)} or by using DOM Level 3 {@link org.w3c.dom.ls.DOMSerializer} and serializing with {@link org.w3c.dom.ls.DOMSerializer#write}, {@link org.w3c.dom.ls.DOMSerializer#writeToString}.
If an I/O exception occurs while serializing, the serializer will not throw an exception directly, but only throw it at the end of serializing (either DOM or SAX's {@link org.xml.sax.DocumentHandler#endDocument}.
For elements that are not specified as whitespace preserving, the serializer will potentially break long text lines at space boundaries, indent lines, and serialize elements on separate lines. Line terminators will be regarded as spaces, and spaces at beginning of line will be stripped.
Version: $Revision: 1.66 $ $Date: 2005/05/03 11:12:21 $
See Also: Serializer
Field Summary | |
---|---|
protected static boolean | DEBUG |
protected NamespaceSupport | fLocalNSBinder stores all namespace bindings on the current element |
protected boolean | fNamespacePrefixes
Controls whether namespace prefixes will be printed out during serialization |
protected boolean | fNamespaces
Controls whether namespace fixup should be performed during
the serialization.
|
protected NamespaceSupport | fNSBinder stores namespaces in scope |
protected SymbolTable | fSymbolTable symbol table for serialization |
protected static String | PREFIX |
Constructor Summary | |
---|---|
XMLSerializer()
Constructs a new serializer. | |
XMLSerializer(OutputFormat format)
Constructs a new serializer. | |
XMLSerializer(Writer writer, OutputFormat format)
Constructs a new serializer that writes to the specified writer
using the specified output format. | |
XMLSerializer(OutputStream output, OutputFormat format)
Constructs a new serializer that writes to the specified output
stream using the specified output format. |
Method Summary | |
---|---|
protected void | checkUnboundNamespacePrefixedNode(Node node)
DOM Level 3:
Check a node to determine if it contains unbound namespace prefixes.
|
void | endElement(String namespaceURI, String localName, String rawName) |
void | endElement(String tagName) |
void | endElementIO(String namespaceURI, String localName, String rawName) |
protected String | getEntityRef(int ch) |
protected void | printEscaped(String source) |
protected void | printText(String text, boolean preserveSpace, boolean unescaped) |
protected void | printText(char[] chars, int start, int length, boolean preserveSpace, boolean unescaped) |
protected void | printXMLChar(int ch) print text data |
boolean | reset() |
protected void | serializeElement(Element elem)
Called to serialize a DOM element. |
void | setNamespaces(boolean namespaces)
This methods turns on namespace fixup algorithm during
DOM serialization. |
void | setOutputFormat(OutputFormat format) |
protected void | startDocument(String rootTagName)
Called to serialize the document's DOCTYPE by the root element.
|
void | startElement(String namespaceURI, String localName, String rawName, Attributes attrs) |
void | startElement(String tagName, AttributeList attrs) |
Parameters: writer The writer to use format The output format to use, null for the default
Parameters: output The output stream to use format The output format to use, null for the default
Parameters: node The node to check for unbound namespace prefices
Parameters: namespaces
See Also: org.w3c.dom.ls.DOMSerializer
This method will check if it has not been called before ({@link #_started}), will serialize the document type declaration, and will serialize all pre-root comments and PIs that were accumulated in the document (see {@link #serializePreRoot}). Pre-root will be serialized even if this is not the first root element of the document.