Package name.jurgenei.gradle.xml
Class SaxXmlWriter
java.lang.Object
name.jurgenei.gradle.xml.SaxXmlWriter
Minimal SAX XML writer with pretty-print output and helper methods for namespace-aware emission.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordAttribute descriptor used by element helper methods. -
Method Summary
Modifier and TypeMethodDescriptionvoidappendFragment(String fragment, Map<String, String> namespaceHints) Parses and appends XML fragment under secure parser settings.static SaxXmlWriter.XmlAttributeCreates non-namespaced attribute.static SaxXmlWriter.XmlAttributeCreates namespaced attribute.build()Returns rendered XML output.voidEmits XML comment.static SaxXmlWriterCreates pretty-printing SAX writer with secure transformer defaults.voidemptyElement(String namespaceUri, String localName, String qName, List<SaxXmlWriter.XmlAttribute> attributes, Map<String, String> namespaceMappings) Emits empty element with optional attributes and namespace mappings.voidCompletes XML document emission.voidendElement(String namespaceUri, String localName, String qName) Ends element and closes namespace declarations opened for it.voidStarts XML document emission.voidstartElement(String namespaceUri, String localName, String qName, List<SaxXmlWriter.XmlAttribute> attributes, Map<String, String> namespaceMappings) Starts element with optional namespace declarations and attributes.voidEmits text node.
-
Method Details
-
createPretty
Creates pretty-printing SAX writer with secure transformer defaults.- Returns:
- initialized XML writer instance
-
startDocument
Starts XML document emission.- Throws:
SAXException- if downstream handler fails
-
endDocument
Completes XML document emission.- Throws:
SAXException- if downstream handler fails
-
startElement
public void startElement(String namespaceUri, String localName, String qName, List<SaxXmlWriter.XmlAttribute> attributes, Map<String, String> namespaceMappings) throws SAXExceptionStarts element with optional namespace declarations and attributes.- Parameters:
namespaceUri- namespace URI or empty stringlocalName- local element nameqName- qualified element nameattributes- optional element attributesnamespaceMappings- optional prefix to URI mappings declared on this element- Throws:
SAXException- if downstream handler fails
-
endElement
Ends element and closes namespace declarations opened for it.- Parameters:
namespaceUri- namespace URI or empty stringlocalName- local element nameqName- qualified element name- Throws:
SAXException- if downstream handler fails
-
emptyElement
public void emptyElement(String namespaceUri, String localName, String qName, List<SaxXmlWriter.XmlAttribute> attributes, Map<String, String> namespaceMappings) throws SAXExceptionEmits empty element with optional attributes and namespace mappings.- Parameters:
namespaceUri- namespace URI or empty stringlocalName- local element nameqName- qualified element nameattributes- optional element attributesnamespaceMappings- optional prefix to URI mappings declared on this element- Throws:
SAXException- if downstream handler fails
-
text
Emits text node.- Parameters:
text- text content; blank values are ignored- Throws:
SAXException- if downstream handler fails
-
comment
Emits XML comment.- Parameters:
text- comment text; blank values are ignored- Throws:
SAXException- if downstream handler fails
-
appendFragment
Parses and appends XML fragment under secure parser settings.- Parameters:
fragment- XML fragment to appendnamespaceHints- optional namespace hints used while wrapping fragment root
-
build
Returns rendered XML output.- Returns:
- serialized XML string
-
attr
Creates non-namespaced attribute.- Parameters:
name- attribute namevalue- attribute value- Returns:
- attribute descriptor
-
attr
public static SaxXmlWriter.XmlAttribute attr(String namespaceUri, String localName, String qName, String value) Creates namespaced attribute.- Parameters:
namespaceUri- namespace URI or nulllocalName- local name or nullqName- qualified namevalue- attribute value- Returns:
- attribute descriptor
-