net.sf.saxon.event

Class XMLEmitter

public class XMLEmitter extends Emitter

XMLEmitter is an Emitter that generates XML output to a specified destination.
Field Summary
protected booleandeclarationIsWritten
protected intelementCode
protected StackelementStack
protected booleanopenStartTag
protected booleanpreferHex
static boolean[]specialInAtt
static boolean[]specialInText
protected booleanstarted
protected booleanstartedElement
protected booleanundeclareNamespaces
Method Summary
voidattribute(int nameCode, int typeCode, CharSequence value, int locationId, int properties)
voidcharacters(CharSequence chars, int locationId, int properties)
Character data.
voidclose()
End of the document.
voidcloseStartTag()
Mark the end of the start tag
voidcomment(CharSequence chars, int locationId, int properties)
Handle a comment.
protected StringemptyElementTagCloser(String displayName, int nameCode)
Close an empty element tag.
voidendDocument()
Notify the end of a document node
voidendElement()
End of an element.
protected StringgetCachedName(int nameCode)
Get a name from the local name cache
voidnamespace(int namespaceCode, int properties)
voidopen()
Start of the event stream.
protected voidopenDocument()
Do the real work of starting the document.
protected voidoutputCharacterReference(int charval)
voidprocessingInstruction(String target, CharSequence data, int locationId, int properties)
Handle a processing instruction.
protected voidputCachedName(int nameCode, String displayName)
Add a name to the local name cache
voidstartContent()
voidstartDocument(int properties)
Start of a document node.
voidstartElement(int nameCode, int typeCode, int locationId, int properties)
Start of an element.
protected inttestCharacters(CharSequence chars)
Test that all characters in a name (for example) are supported in the target encoding.
booleanusesTypeAnnotations()
Ask whether this Receiver (or the downstream pipeline) makes any use of the type annotations supplied on element and attribute events
protected voidwriteAttribute(int elCode, String attname, CharSequence value, int properties)
Write attribute name=value pair.
voidwriteCharSequence(CharSequence s)
Write a CharSequence (without any escaping of special characters): various implementations
voidwriteDeclaration()
Output the XML declaration
protected voidwriteDocType(String type, String systemId, String publicId)
Output the document type declaration
protected voidwriteEscape(CharSequence chars, boolean inAttribute)
Write contents of array to current writer, after escaping special characters.

Field Detail

declarationIsWritten

protected boolean declarationIsWritten

elementCode

protected int elementCode

elementStack

protected Stack elementStack

openStartTag

protected boolean openStartTag

preferHex

protected boolean preferHex

specialInAtt

static boolean[] specialInAtt

specialInText

static boolean[] specialInText

started

protected boolean started

startedElement

protected boolean startedElement

undeclareNamespaces

protected boolean undeclareNamespaces

Method Detail

attribute

public void attribute(int nameCode, int typeCode, CharSequence value, int locationId, int properties)

characters

public void characters(CharSequence chars, int locationId, int properties)
Character data.

close

public void close()
End of the document.

closeStartTag

public void closeStartTag()
Mark the end of the start tag

Throws: XPathException if an IO exception occurs

comment

public void comment(CharSequence chars, int locationId, int properties)
Handle a comment.

emptyElementTagCloser

protected String emptyElementTagCloser(String displayName, int nameCode)
Close an empty element tag. (This is overridden in XHTMLEmitter).

Parameters: displayName the name of the empty element nameCode the fingerprint of the name of the empty element

Returns: the string used to close an empty element tag.

endDocument

public void endDocument()
Notify the end of a document node

endElement

public void endElement()
End of an element.

getCachedName

protected String getCachedName(int nameCode)
Get a name from the local name cache

Parameters: nameCode the integer name code

Returns: a lexical QName if the name is in the cache; otherwise, null

namespace

public void namespace(int namespaceCode, int properties)

open

public void open()
Start of the event stream. Nothing is done at this stage: the opening of the output file is deferred until some content is written to it.

openDocument

protected void openDocument()
Do the real work of starting the document. This happens when the first content is written.

Throws: XPathException

outputCharacterReference

protected void outputCharacterReference(int charval)

processingInstruction

public void processingInstruction(String target, CharSequence data, int locationId, int properties)
Handle a processing instruction.

putCachedName

protected void putCachedName(int nameCode, String displayName)
Add a name to the local name cache

Parameters: nameCode the integer name code displayName the corresponding lexical QName

startContent

public void startContent()

startDocument

public void startDocument(int properties)
Start of a document node. Nothing is done at this stage: the opening of the output file is deferred until some content is written to it.

startElement

public void startElement(int nameCode, int typeCode, int locationId, int properties)
Start of an element. Output the start tag, escaping special characters.

testCharacters

protected int testCharacters(CharSequence chars)
Test that all characters in a name (for example) are supported in the target encoding.

Parameters: chars the characters to be tested

Returns: zero if all the characters are available, or the value of the first offending character if not

usesTypeAnnotations

public boolean usesTypeAnnotations()
Ask whether this Receiver (or the downstream pipeline) makes any use of the type annotations supplied on element and attribute events

Returns: true if the Receiver makes any use of this information. If false, the caller may supply untyped nodes instead of supplying the type annotation

writeAttribute

protected void writeAttribute(int elCode, String attname, CharSequence value, int properties)
Write attribute name=value pair.

Parameters: elCode The element name is not used in this version of the method, but is used in the HTML subclass. attname The attribute name, which has already been validated to ensure it can be written in this encoding value The value of the attribute properties Any special properties of the attribute

writeCharSequence

public void writeCharSequence(CharSequence s)
Write a CharSequence (without any escaping of special characters): various implementations

Parameters: s the character sequence to be written

writeDeclaration

public void writeDeclaration()
Output the XML declaration

writeDocType

protected void writeDocType(String type, String systemId, String publicId)
Output the document type declaration

Parameters: type The element name systemId The DOCTYP system identifier publicId The DOCTYPE public identifier

writeEscape

protected void writeEscape(CharSequence chars, boolean inAttribute)
Write contents of array to current writer, after escaping special characters. This method converts the XML special characters (such as < and &) into their predefined entities.

Parameters: chars The character sequence containing the string inAttribute Set to true if the text is in an attribute value