Class SAXOutputter
- java.lang.Object
-
- eu.maveniverse.domtrip.sax.SAXOutputter
-
public class SAXOutputter extends java.lang.ObjectEmits SAXContentHandlerevents from a domtripDocumentorElementtree.This enables domtrip to participate in SAX-based XML processing pipelines such as XSLT processors, XML validators, serializers, and content pipelines. Rather than serializing to a string and re-parsing, the SAXOutputter walks the domtrip tree directly and emits the corresponding SAX events.
Note: Formatting preservation is intentionally lost at this boundary since SAX events do not carry formatting metadata. The value is interoperability, not round-tripping through SAX.
Usage Examples:
Document doc = Document.of(xml); // Feed into a ContentHandler SAXOutputter outputter = new SAXOutputter(); outputter.output(doc, contentHandler); // With a LexicalHandler for comments and CDATA outputter.output(doc, contentHandler, lexicalHandler); // Output a single element subtree outputter.output(element, contentHandler);Namespace Handling:
The outputter emits
startPrefixMapping/endPrefixMappingevents for namespace declarations on each element. By default, namespace declaration attributes (xmlns,xmlns:prefix) are not included in theAttributesparameter ofstartElement. SetsetReportNamespaceDeclarations(boolean)totrueto include them, matching the SAXnamespace-prefixesfeature behavior.- Since:
- 1.3.0
- See Also:
DomTripSAXSource,DomTripXMLReader
-
-
Constructor Summary
Constructors Constructor Description SAXOutputter()Creates a new SAXOutputter with default settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisReportNamespaceDeclarations()Returns whether namespace declarations are reported as attributes.voidoutput(Document doc, org.xml.sax.ContentHandler handler)Emits SAX events for the given document to the specified content handler.voidoutput(Document doc, org.xml.sax.ContentHandler handler, org.xml.sax.ext.LexicalHandler lexicalHandler)Emits SAX events for the given document to the specified content and lexical handlers.voidoutput(Element element, org.xml.sax.ContentHandler handler)Emits SAX events for the given element subtree to the specified content handler.voidoutput(Element element, org.xml.sax.ContentHandler handler, org.xml.sax.ext.LexicalHandler lexicalHandler)Emits SAX events for the given element subtree to the specified handlers.voidsetReportNamespaceDeclarations(boolean reportNamespaceDeclarations)Sets whether namespace declarations should be reported as attributes instartElementcalls.
-
-
-
Method Detail
-
isReportNamespaceDeclarations
public boolean isReportNamespaceDeclarations()
Returns whether namespace declarations are reported as attributes.- Returns:
trueif namespace declarations are included instartElementattributes
-
setReportNamespaceDeclarations
public void setReportNamespaceDeclarations(boolean reportNamespaceDeclarations)
Sets whether namespace declarations should be reported as attributes instartElementcalls.When
true,xmlnsandxmlns:prefixattributes are included in theAttributesparameter, matching the SAXnamespace-prefixesfeature.- Parameters:
reportNamespaceDeclarations-trueto include namespace declaration attributes
-
output
public void output(Document doc, org.xml.sax.ContentHandler handler) throws org.xml.sax.SAXException
Emits SAX events for the given document to the specified content handler.- Parameters:
doc- the document to outputhandler- the content handler to receive events- Throws:
org.xml.sax.SAXException- if the content handler reports an errorjava.lang.IllegalArgumentException- if doc or handler is null
-
output
public void output(Document doc, org.xml.sax.ContentHandler handler, org.xml.sax.ext.LexicalHandler lexicalHandler) throws org.xml.sax.SAXException
Emits SAX events for the given document to the specified content and lexical handlers.The lexical handler receives events for comments and CDATA sections. If
null, comments and CDATA boundaries are silently skipped (CDATA text content is still emitted as regular characters).- Parameters:
doc- the document to outputhandler- the content handler to receive eventslexicalHandler- the lexical handler for comments and CDATA, or null- Throws:
org.xml.sax.SAXException- if a handler reports an errorjava.lang.IllegalArgumentException- if doc or handler is null
-
output
public void output(Element element, org.xml.sax.ContentHandler handler) throws org.xml.sax.SAXException
Emits SAX events for the given element subtree to the specified content handler.Unlike
output(Document, ContentHandler), this method does not emitstartDocument/endDocumentevents.- Parameters:
element- the element to outputhandler- the content handler to receive events- Throws:
org.xml.sax.SAXException- if the content handler reports an errorjava.lang.IllegalArgumentException- if element or handler is null
-
output
public void output(Element element, org.xml.sax.ContentHandler handler, org.xml.sax.ext.LexicalHandler lexicalHandler) throws org.xml.sax.SAXException
Emits SAX events for the given element subtree to the specified handlers.Unlike
output(Document, ContentHandler, LexicalHandler), this method does not emitstartDocument/endDocumentevents.- Parameters:
element- the element to outputhandler- the content handler to receive eventslexicalHandler- the lexical handler for comments and CDATA, or null- Throws:
org.xml.sax.SAXException- if a handler reports an errorjava.lang.IllegalArgumentException- if element or handler is null
-
-