Top Description Fields Constructors Methods
org.apache.xml.serialize

public Class XML11Serializer

extends XMLSerializer
Class Inheritance
Imports
java.io.IOException, .OutputStream, .Writer, org.apache.xerces.dom.DOMMessageFormatter, org.apache.xerces.util.NamespaceSupport, .SymbolTable, .XML11Char, .XMLChar, org.w3c.dom.DOMError, .Document, org.xml.sax.SAXException

Deprecated

This class was deprecated in Xerces 2.9.0. It is recommended that new applications use the DOM Level 3 LSSerializer or JAXP's Transformation API for XML (TrAX) for serializing XML. See the Xerces documentation for more information.

Implements an XML serializer supporting both DOM and SAX pretty serializing. For usage instructions see Serializer.

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 serialize(Document) or by using DOM Level 3 org.w3c.dom.ls.LSSerializer and serializing with org.w3c.dom.ls.LSSerializer#write, org.w3c.dom.ls.LSSerializer#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 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.

Authors
Assaf Arkin, Rahul Srivastava, Elena Litani IBM
Version
$Revision: 476047 $ $Date: 2006-11-17 09:57:45 +0530 (Fri, 17 Nov 2006) $
See Also
Serializer

Field Summary

Modifier and TypeField and Description
protected static final boolean
protected boolean
protected NamespaceSupport
fLocalNSBinder

Hides org.apache.xml.serialize.XMLSerializer.fLocalNSBinder.

stores all namespace bindings on the current element
protected int
protected boolean
fNamespaces

Hides org.apache.xml.serialize.XMLSerializer.fNamespaces.

Controls whether namespace fixup should be performed during the serialization.
protected NamespaceSupport
protected SymbolTable
protected static final String
Inherited from org.apache.xml.serialize.XMLSerializer:
fNamespacePrefixes

Constructor Summary

AccessConstructor and Description
public
XML11Serializer()

Constructs a new serializer.

public
XML11Serializer(OutputFormat format)

Deprecated as a consequence of OutputFormat being deprecated.
Constructs a new serializer.
public
XML11Serializer(Writer
The writer to use
writer
,
OutputFormat
The output format to use, null for the default
format
)

Deprecated as a consequence of OutputFormat being deprecated.
Constructs a new serializer that writes to the specified writer using the specified output format.
public
XML11Serializer(OutputStream
The output stream to use
output
,
OutputFormat
The output format to use, null for the default
format
)

Deprecated as a consequence of OutputFormat being deprecated.
Constructs a new serializer that writes to the specified output stream using the specified output format.

Method Summary

Modifier and TypeMethod and Description
public void
characters(char[]
the characters from the XML document
chars
,
int
the start position in the array
start
,
int
the number of characters to read from the array
length
)

Overrides org.apache.xml.serialize.BaseMarkupSerializer.characters.

Implements org.xml.sax.ContentHandler.characters, org.xml.sax.DocumentHandler.characters.

Receive notification of character data.
protected final void
protected void
printEscaped(String
The string to escape
source
)

Overrides org.apache.xml.serialize.XMLSerializer.printEscaped.

Escapes a string so it may be printed as text content or attribute value.
protected void
printText(String text, boolean preserveSpace, boolean unescaped)

Overrides org.apache.xml.serialize.XMLSerializer.printText.

protected void
printText(char[]
The text to print
chars
,
int
The start offset
start
,
int
The number of characters
length
,
boolean
Space preserving flag
preserveSpace
,
boolean
Print unescaped
unescaped
)

Overrides org.apache.xml.serialize.XMLSerializer.printText.

Called to print additional text with whitespace handling.
protected final void
public boolean
protected final void
surrogates(int high, int low, boolean inContent)

Overrides org.apache.xml.serialize.BaseMarkupSerializer.surrogates.

Inherited from org.apache.xml.serialize.XMLSerializer:
checkUnboundNamespacePrefixedNodeendElementendElementendElementIOgetEntityRefserializeElementsetNamespacessetOutputFormatstartDocumentstartElementstartElement

Field Detail

DEBUGback to summary
protected static final boolean DEBUG

Hides org.apache.xml.serialize.XMLSerializer.DEBUG.

fDOML1back to summary
protected boolean fDOML1
fLocalNSBinderback to summary
protected NamespaceSupport fLocalNSBinder

Hides org.apache.xml.serialize.XMLSerializer.fLocalNSBinder.

stores all namespace bindings on the current element

fNamespaceCounterback to summary
protected int fNamespaceCounter
fNamespacesback to summary
protected boolean fNamespaces

Hides org.apache.xml.serialize.XMLSerializer.fNamespaces.

Controls whether namespace fixup should be performed during the serialization.

Note

if this field is set to true the following fields need to be initialized: fNSBinder, fLocalNSBinder, fSymbolTable, XMLSymbols.EMPTY_STRING, fXmlSymbol, fXmlnsSymbol, fNamespaceCounter.

fNSBinderback to summary
protected NamespaceSupport fNSBinder

Hides org.apache.xml.serialize.XMLSerializer.fNSBinder.

stores namespaces in scope

fSymbolTableback to summary
protected SymbolTable fSymbolTable

Hides org.apache.xml.serialize.XMLSerializer.fSymbolTable.

symbol table for serialization

PREFIXback to summary
protected static final String PREFIX

Hides org.apache.xml.serialize.XMLSerializer.PREFIX.

Constructor Detail

XML11Serializerback to summary
public XML11Serializer()

Constructs a new serializer. The serializer cannot be used without calling setOutputCharStream or setOutputByteStream first.

XML11Serializerback to summary
public XML11Serializer(OutputFormat format)

Deprecated

as a consequence of OutputFormat being deprecated. See corresponding docs for further information.

Constructs a new serializer. The serializer cannot be used without calling setOutputCharStream or setOutputByteStream first.

XML11Serializerback to summary
public XML11Serializer(Writer writer, OutputFormat format)

Deprecated

as a consequence of OutputFormat being deprecated. See corresponding docs for further information.

Constructs a new serializer that writes to the specified writer using the specified output format. If format is null, will use a default output format.

Parameters
writer:Writer

The writer to use

format:OutputFormat

The output format to use, null for the default

XML11Serializerback to summary
public XML11Serializer(OutputStream output, OutputFormat format)

Deprecated

as a consequence of OutputFormat being deprecated. See corresponding docs for further information.

Constructs a new serializer that writes to the specified output stream using the specified output format. If format is null, will use a default output format.

Parameters
output:OutputStream

The output stream to use

format:OutputFormat

The output format to use, null for the default

Method Detail

charactersback to summary
public void characters(char[] chars, int start, int length) throws SAXException

Overrides org.apache.xml.serialize.BaseMarkupSerializer.characters.

Implements org.xml.sax.ContentHandler.characters, org.xml.sax.DocumentHandler.characters.

Doc from org.xml.sax.ContentHandler.characters.

Receive notification of character data.

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.

The application must not attempt to read from the array outside of the specified range.

Individual characters may consist of more than one Java char value. There are two important cases where this happens, because characters can't be represented in just sixteen bits. In one case, characters are represented in a Surrogate Pair, using two special Unicode values. Such characters are in the so-called "Astral Planes", with a code point above U+FFFF. A second case involves composite characters, such as a base character combining with one or more accent characters.

Your code should not assume that algorithms using char-at-a-time idioms will be working in character units; in some cases they will split characters. This is relevant wherever XML permits arbitrary characters, such as attribute values, processing instruction data, and comments as well as in data reported from this method. It's also generally relevant whenever Java code manipulates internationalized text; the issue isn't unique to XML.

Note that some parsers will report whitespace in element content using the ignorableWhitespace method rather than this one (validating parsers must do so).

Parameters
chars:char[]

the characters from the XML document

start:int

the start position in the array

length:int

the number of characters to read from the array

Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
printCDATATextback to summary
protected final void printCDATAText(String text) throws IOException

Overrides org.apache.xml.serialize.BaseMarkupSerializer.printCDATAText.

printEscapedback to summary
protected void printEscaped(String source) throws IOException

Overrides org.apache.xml.serialize.XMLSerializer.printEscaped.

Doc from org.apache.xml.serialize.BaseMarkupSerializer.printEscaped.

Escapes a string so it may be printed as text content or attribute value. Non printable characters are escaped using character references. Where the format specifies a deault entity reference, that reference is used (e.g. <).

Parameters
source:String

The string to escape

printTextback to summary
protected void printText(String text, boolean preserveSpace, boolean unescaped) throws IOException

Overrides org.apache.xml.serialize.XMLSerializer.printText.

printTextback to summary
protected void printText(char[] chars, int start, int length, boolean preserveSpace, boolean unescaped) throws IOException

Overrides org.apache.xml.serialize.XMLSerializer.printText.

Doc from org.apache.xml.serialize.BaseMarkupSerializer.printText.

Called to print additional text with whitespace handling. If spaces are preserved, the text is printed as if by calling printText(String, boolean, boolean) with a call to Printer#breakLine for each new line. If spaces are not preserved, the text is broken at space boundaries if longer than the line width; Multiple spaces are printed as such, but spaces at beginning of line are removed.

Parameters
chars:char[]

The text to print

start:int

The start offset

length:int

The number of characters

preserveSpace:boolean

Space preserving flag

unescaped:boolean

Print unescaped

printXMLCharback to summary
protected final void printXMLChar(int ch) throws IOException

Overrides org.apache.xml.serialize.XMLSerializer.printXMLChar.

Doc from org.apache.xml.serialize.XMLSerializer.printXMLChar.

print text data

resetback to summary
public boolean reset()

Overrides org.apache.xml.serialize.XMLSerializer.reset.

surrogatesback to summary
protected final void surrogates(int high, int low, boolean inContent) throws IOException

Overrides org.apache.xml.serialize.BaseMarkupSerializer.surrogates.