Package org.dom4j.io
Class SAXWriter
java.lang.Object
org.dom4j.io.SAXWriter
- All Implemented Interfaces:
XMLReader
SAXWriter
writes a DOM4J tree to a SAX ContentHandler.
- Version:
- $Revision: 1.24 $
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AttributesImpl
AttributesImpl
used when generating the Attributesprivate ContentHandler
ContentHandler
to which SAX events are raisedprivate boolean
Whether namespace declarations are exported as attributes or notprivate DTDHandler
DTDHandler
fired when a document has a DTDprivate EntityResolver
EntityResolver
fired when a document has a DTDprivate ErrorHandler
protected static final String
protected static final String
Stores the featuresprotected static final String[]
private LexicalHandler
LexicalHandler
fired on Entity and CDATA sectionsStores the properties -
Constructor Summary
ConstructorsConstructorDescriptionSAXWriter
(ContentHandler contentHandler) SAXWriter
(ContentHandler contentHandler, LexicalHandler lexicalHandler) SAXWriter
(ContentHandler contentHandler, LexicalHandler lexicalHandler, EntityResolver entityResolver) -
Method Summary
Modifier and TypeMethodDescriptionprotected AttributesImpl
addNamespaceAttribute
(AttributesImpl attrs, Namespace namespace) If isDelcareNamespaceAttributes() is enabled then this method will add the given namespace declaration to the supplied attributes object, creating one if it does not exist.protected void
Ensures non-null content handlers?protected Attributes
createAttributes
(Element element, Attributes namespaceAttributes) protected void
documentLocator
(Document document) TheLocator
is only really useful when parsing a textual document as its main purpose is to identify the line and column number.protected void
dtdHandler
(Document document) We do not yet support DTD or XML Schemas so this method does nothing right now.protected void
protected void
endElement
(Element element) protected void
endPrefixMapping
(NamespaceStack stack, int stackSize) Fires a SAX endPrefixMapping event for all the namespaceStack which have gone out of scopeprotected void
entityResolver
(Document document) DOCUMENT ME!DOCUMENT ME!DOCUMENT ME!DOCUMENT ME!boolean
getFeature
(String name) Looks up the value of a feature.DOCUMENT ME!getProperty
(String name) Gets the given SAX propertyboolean
Should namespace declarations be converted to "xmlns" attributes.protected boolean
isIgnoreableNamespace
(Namespace namespace, NamespaceStack namespaceStack) DOCUMENT ME!void
This method is not supported.void
parse
(InputSource input) Parses an XML document.void
setContentHandler
(ContentHandler contentHandler) Sets theContentHandler
called when SAX events are raisedvoid
setDeclareNamespaceAttributes
(boolean declareNamespaceAttrs) Sets whether namespace declarations should be exported as "xmlns" attributes or not.void
setDTDHandler
(DTDHandler handler) Sets theDTDHandler
.void
setEntityResolver
(EntityResolver entityResolver) Sets theEntityResolver
.void
setErrorHandler
(ErrorHandler errorHandler) Sets theErrorHandler
.void
setFeature
(String name, boolean value) This implementation does actually use any features but just stores them for later retrievalvoid
setLexicalHandler
(LexicalHandler lexicalHandler) Sets theLexicalHandler
.void
setProperty
(String name, Object value) Sets the given SAX propertyvoid
setXMLReader
(XMLReader xmlReader) Sets theXMLReader
used to write SAX events toprotected void
protected void
startElement
(Element element, AttributesImpl namespaceAttributes) protected AttributesImpl
startPrefixMapping
(Element element, NamespaceStack namespaceStack) Fires a SAX startPrefixMapping event for all the namespaceStack which have just come into scopevoid
Generates SAX events for the given textvoid
Generates SAX events for the given CDATAvoid
Generates SAX events for the given Commentvoid
Generates SAX events for the given Document and all its contentvoid
Generates SAX events for the given Element and all its contentprotected void
write
(Element element, NamespaceStack namespaceStack) void
Generates SAX events for the given Entityvoid
A polymorphic method to write any Node to this SAX streamvoid
Generates SAX events for the given ProcessingInstructionvoid
writeClose
(Element element) Writes the closing tag of anElement
protected void
writeContent
(Branch branch, NamespaceStack namespaceStack) void
-
Field Details
-
LEXICAL_HANDLER_NAMES
-
FEATURE_NAMESPACE_PREFIXES
- See Also:
-
FEATURE_NAMESPACES
- See Also:
-
contentHandler
ContentHandler
to which SAX events are raised -
dtdHandler
DTDHandler
fired when a document has a DTD -
entityResolver
EntityResolver
fired when a document has a DTD -
errorHandler
-
lexicalHandler
LexicalHandler
fired on Entity and CDATA sections -
attributes
AttributesImpl
used when generating the Attributes -
features
Stores the features -
properties
Stores the properties -
declareNamespaceAttributes
private boolean declareNamespaceAttributesWhether namespace declarations are exported as attributes or not
-
-
Constructor Details
-
SAXWriter
public SAXWriter() -
SAXWriter
-
SAXWriter
-
SAXWriter
public SAXWriter(ContentHandler contentHandler, LexicalHandler lexicalHandler, EntityResolver entityResolver)
-
-
Method Details
-
write
A polymorphic method to write any Node to this SAX stream- Parameters:
node
- DOCUMENT ME!- Throws:
SAXException
- DOCUMENT ME!
-
write
Generates SAX events for the given Document and all its content- Parameters:
document
- is the Document to parse- Throws:
SAXException
- if there is a SAX error processing the events
-
write
Generates SAX events for the given Element and all its content- Parameters:
element
- is the Element to parse- Throws:
SAXException
- if there is a SAX error processing the events
-
writeOpen
- Parameters:
element
-Element
to output.- Throws:
SAXException
- DOCUMENT ME!
-
writeClose
Writes the closing tag of an
Element
- Parameters:
element
-Element
to output.- Throws:
SAXException
- DOCUMENT ME!
-
write
Generates SAX events for the given text- Parameters:
text
- is the text to send to the SAX ContentHandler- Throws:
SAXException
- if there is a SAX error processing the events
-
write
Generates SAX events for the given CDATA- Parameters:
cdata
- is the CDATA to parse- Throws:
SAXException
- if there is a SAX error processing the events
-
write
Generates SAX events for the given Comment- Parameters:
comment
- is the Comment to parse- Throws:
SAXException
- if there is a SAX error processing the events
-
write
Generates SAX events for the given Entity- Parameters:
entity
- is the Entity to parse- Throws:
SAXException
- if there is a SAX error processing the events
-
write
Generates SAX events for the given ProcessingInstruction- Parameters:
pi
- is the ProcessingInstruction to parse- Throws:
SAXException
- if there is a SAX error processing the events
-
isDeclareNamespaceAttributes
public boolean isDeclareNamespaceAttributes()Should namespace declarations be converted to "xmlns" attributes. This property defaults tofalse
as per the SAX specification. This property is set via the SAX feature "http://xml.org/sax/features/namespace-prefixes"- Returns:
- DOCUMENT ME!
-
setDeclareNamespaceAttributes
public void setDeclareNamespaceAttributes(boolean declareNamespaceAttrs) Sets whether namespace declarations should be exported as "xmlns" attributes or not. This property is set from the SAX feature "http://xml.org/sax/features/namespace-prefixes"- Parameters:
declareNamespaceAttrs
- DOCUMENT ME!
-
getContentHandler
DOCUMENT ME!- Specified by:
getContentHandler
in interfaceXMLReader
- Returns:
- the
ContentHandler
called when SAX events are raised
-
setContentHandler
Sets theContentHandler
called when SAX events are raised- Specified by:
setContentHandler
in interfaceXMLReader
- Parameters:
contentHandler
- is theContentHandler
called when SAX events are raised
-
getDTDHandler
DOCUMENT ME!- Specified by:
getDTDHandler
in interfaceXMLReader
- Returns:
- the
DTDHandler
-
setDTDHandler
Sets theDTDHandler
.- Specified by:
setDTDHandler
in interfaceXMLReader
- Parameters:
handler
- DOCUMENT ME!
-
getErrorHandler
DOCUMENT ME!- Specified by:
getErrorHandler
in interfaceXMLReader
- Returns:
- the
ErrorHandler
-
setErrorHandler
Sets theErrorHandler
.- Specified by:
setErrorHandler
in interfaceXMLReader
- Parameters:
errorHandler
- DOCUMENT ME!
-
getEntityResolver
DOCUMENT ME!- Specified by:
getEntityResolver
in interfaceXMLReader
- Returns:
- the
EntityResolver
used when a Document contains a DTD
-
setEntityResolver
Sets theEntityResolver
.- Specified by:
setEntityResolver
in interfaceXMLReader
- Parameters:
entityResolver
- is theEntityResolver
-
getLexicalHandler
DOCUMENT ME!- Returns:
- the
LexicalHandler
used when a Document contains a DTD
-
setLexicalHandler
Sets theLexicalHandler
.- Parameters:
lexicalHandler
- is theLexicalHandler
-
setXMLReader
Sets theXMLReader
used to write SAX events to- Parameters:
xmlReader
- is theXMLReader
-
getFeature
Looks up the value of a feature.- Specified by:
getFeature
in interfaceXMLReader
- Parameters:
name
- DOCUMENT ME!- Returns:
- DOCUMENT ME!
- Throws:
SAXNotRecognizedException
- DOCUMENT ME!SAXNotSupportedException
- DOCUMENT ME!
-
setFeature
public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException This implementation does actually use any features but just stores them for later retrieval- Specified by:
setFeature
in interfaceXMLReader
- Parameters:
name
- DOCUMENT ME!value
- DOCUMENT ME!- Throws:
SAXNotRecognizedException
- DOCUMENT ME!SAXNotSupportedException
- DOCUMENT ME!
-
setProperty
Sets the given SAX property- Specified by:
setProperty
in interfaceXMLReader
- Parameters:
name
- DOCUMENT ME!value
- DOCUMENT ME!
-
getProperty
Gets the given SAX property- Specified by:
getProperty
in interfaceXMLReader
- Parameters:
name
- DOCUMENT ME!- Returns:
- DOCUMENT ME!
- Throws:
SAXNotRecognizedException
- DOCUMENT ME!SAXNotSupportedException
- DOCUMENT ME!
-
parse
This method is not supported.- Specified by:
parse
in interfaceXMLReader
- Parameters:
systemId
- DOCUMENT ME!- Throws:
SAXNotSupportedException
- DOCUMENT ME!
-
parse
Parses an XML document. This method can only accept DocumentInputSource inputs otherwise aSAXNotSupportedException
exception is thrown.- Specified by:
parse
in interfaceXMLReader
- Parameters:
input
- DOCUMENT ME!- Throws:
SAXException
- DOCUMENT ME!SAXNotSupportedException
- if the input source is not wrapping a dom4j document
-
writeContent
- Throws:
SAXException
-
documentLocator
TheLocator
is only really useful when parsing a textual document as its main purpose is to identify the line and column number. Since we are processing an in memory tree which will probably have its line number information removed, we'll just use -1 for the line and column numbers.- Parameters:
document
- DOCUMENT ME!- Throws:
SAXException
- DOCUMENT ME!
-
entityResolver
- Throws:
SAXException
-
dtdHandler
We do not yet support DTD or XML Schemas so this method does nothing right now.- Parameters:
document
- DOCUMENT ME!- Throws:
SAXException
- DOCUMENT ME!
-
startDocument
- Throws:
SAXException
-
endDocument
- Throws:
SAXException
-
write
- Throws:
SAXException
-
startPrefixMapping
protected AttributesImpl startPrefixMapping(Element element, NamespaceStack namespaceStack) throws SAXException Fires a SAX startPrefixMapping event for all the namespaceStack which have just come into scope- Parameters:
element
- DOCUMENT ME!namespaceStack
- DOCUMENT ME!- Returns:
- DOCUMENT ME!
- Throws:
SAXException
- DOCUMENT ME!
-
endPrefixMapping
Fires a SAX endPrefixMapping event for all the namespaceStack which have gone out of scope- Parameters:
stack
- DOCUMENT ME!stackSize
- DOCUMENT ME!- Throws:
SAXException
- DOCUMENT ME!
-
startElement
protected void startElement(Element element, AttributesImpl namespaceAttributes) throws SAXException - Throws:
SAXException
-
endElement
- Throws:
SAXException
-
createAttributes
protected Attributes createAttributes(Element element, Attributes namespaceAttributes) throws SAXException - Throws:
SAXException
-
addNamespaceAttribute
If isDelcareNamespaceAttributes() is enabled then this method will add the given namespace declaration to the supplied attributes object, creating one if it does not exist.- Parameters:
attrs
- DOCUMENT ME!namespace
- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
isIgnoreableNamespace
DOCUMENT ME!- Parameters:
namespace
- DOCUMENT ME!namespaceStack
- DOCUMENT ME!- Returns:
- true if the given namespace is an ignorable namespace (such as Namespace.NO_NAMESPACE or Namespace.XML_NAMESPACE) or if the namespace has already been declared in the current scope
-
checkForNullHandlers
protected void checkForNullHandlers()Ensures non-null content handlers?
-