net.sf.saxon.event

Class XMLEmitter

Implemented Interfaces:
Result, Receiver
Known Direct Subclasses:
HTMLEmitter, MessageEmitter, MessageWarner, TEXTEmitter, XHTMLEmitter, XQueryEmitter

public class XMLEmitter
extends Emitter

XMLEmitter is an Emitter that generates XML output to a specified destination.

Field Summary

protected boolean
declarationIsWritten
protected int
elementCode
protected Stack
elementStack
protected boolean
empty
protected boolean
openStartTag
protected boolean
preferHex
protected boolean
undeclareNamespaces

Fields inherited from class net.sf.saxon.event.Emitter

allCharactersEncodable, characterSet, namePool, outputProperties, outputStream, pipelineConfig, streamResult, systemId, writer

Method Summary

void
attribute(int nameCode, int typeCode, CharSequence value, int locationId, int properties)
void
characters(CharSequence chars, int locationId, int properties)
Character data.
void
close()
End of the document.
void
closeStartTag()
Mark the end of the start tag
void
comment(CharSequence chars, int locationId, int properties)
Handle a comment.
protected String
emptyElementTagCloser(String displayName, int nameCode)
Close an empty element tag.
void
endDocument()
Notify the end of a document node
void
endElement()
End of an element.
void
namespace(int namespaceCode, int properties)
void
open()
Start of the event stream.
protected void
openDocument()
Do the real work of starting the document.
protected void
outputCharacterReference(int charval)
void
processingInstruction(String target, CharSequence data, int locationId, int properties)
Handle a processing instruction.
void
startContent()
void
startDocument(int properties)
Start of a document node.
void
startElement(int nameCode, int typeCode, int locationId, int properties)
Start of an element.
protected int
testCharacters(CharSequence chars)
Test that all characters in a name (for example) are supported in the target encoding.
protected void
writeAttribute(int elCode, String attname, CharSequence value, int properties)
Write attribute name=value pair.
void
writeCharSequence(CharSequence s)
Write a CharSequence (without any escaping of special characters): various implementations
void
writeDeclaration()
Output the XML declaration
protected void
writeDocType(String type, String systemId, String publicId)
Output the document type declaration
protected void
writeEscape(CharSequence chars, boolean inAttribute)
Write contents of array to current writer, after escaping special characters.

Methods inherited from class net.sf.saxon.event.Emitter

getConfiguration, getOutputProperties, getOutputStream, getPipelineConfiguration, getSystemId, getWriter, makeWriter, setOutputProperties, setOutputStream, setPipelineConfiguration, setStreamResult, setSystemId, setUnparsedEntity, setWriter, usesWriter

Field Details

declarationIsWritten

protected boolean declarationIsWritten

elementCode

protected int elementCode

elementStack

protected Stack elementStack

empty

protected boolean empty

openStartTag

protected boolean openStartTag

preferHex

protected boolean preferHex

undeclareNamespaces

protected boolean undeclareNamespaces

Method Details

attribute

public void attribute(int nameCode,
                      int typeCode,
                      CharSequence value,
                      int locationId,
                      int properties)
            throws XPathException
Specified by:
attribute in interface Receiver

characters

public void characters(CharSequence chars,
                       int locationId,
                       int properties)
            throws XPathException
Character data.
Specified by:
characters in interface Receiver

close

public void close()
            throws XPathException
End of the document.
Specified by:
close in interface Receiver

closeStartTag

public void closeStartTag()
            throws XPathException
Mark the end of the start tag
Throws:
XPathException - if an IO exception occurs

comment

public void comment(CharSequence chars,
                    int locationId,
                    int properties)
            throws XPathException
Handle a comment.
Specified by:
comment in interface Receiver

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()
            throws XPathException
Notify the end of a document node
Specified by:
endDocument in interface Receiver

endElement

public void endElement()
            throws XPathException
End of an element.
Specified by:
endElement in interface Receiver

namespace

public void namespace(int namespaceCode,
                      int properties)
            throws XPathException
Specified by:
namespace in interface Receiver

open

public void open()
            throws XPathException
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.
Specified by:
open in interface Receiver

openDocument

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

outputCharacterReference

protected void outputCharacterReference(int charval)
            throws java.io.IOException

processingInstruction

public void processingInstruction(String target,
                                  CharSequence data,
                                  int locationId,
                                  int properties)
            throws XPathException
Handle a processing instruction.
Specified by:
processingInstruction in interface Receiver

startContent

public void startContent()
            throws XPathException
Specified by:
startContent in interface Receiver

startDocument

public void startDocument(int properties)
            throws XPathException
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.
Specified by:
startDocument in interface Receiver

startElement

public void startElement(int nameCode,
                         int typeCode,
                         int locationId,
                         int properties)
            throws XPathException
Start of an element. Output the start tag, escaping special characters.
Specified by:
startElement in interface Receiver

testCharacters

protected int testCharacters(CharSequence chars)
            throws XPathException
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

writeAttribute

protected void writeAttribute(int elCode,
                              String attname,
                              CharSequence value,
                              int properties)
            throws XPathException
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)
            throws java.io.IOException
Write a CharSequence (without any escaping of special characters): various implementations
Parameters:
s - the character sequence to be written

writeDeclaration

public void writeDeclaration()
            throws XPathException
Output the XML declaration

writeDocType

protected void writeDocType(String type,
                            String systemId,
                            String publicId)
            throws XPathException
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)
            throws java.io.IOException,
                   XPathException
Write contents of array to current writer, after escaping special characters. This method converts the XML special characters (such as <32and &) into their predefined entities.
Parameters:
chars - The character sequence containing the string
inAttribute - Set to true if the text is in an attribute value