Package com.day.cq.commons
Class SimpleXml
java.lang.Object
com.day.cq.commons.SimpleXml
The
SimpleXml class facilitates the creation of an XML document.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassTheSimpleXml.Elementreperesents an XML element. -
Constructor Summary
ConstructorsConstructorDescriptionCreates aSimpleXmlinstance using the specified print writer for the output of the XML document. -
Method Summary
Modifier and TypeMethodDescriptionclose()Closes the most recent open element.voidCloses the XML document after closing all open elements.Returns the print writer used for the output of the XML document.omitXmlDeclaration(boolean omit) Defines whether the XML declaration should be omitted.open()Opens the XML document.Opens and returns a new XML element with the specified name.Opens and returns a new XML element with the specified name.Opens and returns a new XML element with the specified name and content.Opens and returns a new XML element with the specified name.Opens the XML document.setDocumentLocator(Locator locator) Sets the document locator of the output.setEncoding(String encoding) Sets the character encoding of the output.setIndent(boolean indent) Defines whether the output should use indetation.tidyUp()Closes all currently open elements.
-
Constructor Details
-
SimpleXml
Creates aSimpleXmlinstance using the specified print writer for the output of the XML document.- Parameters:
w- The writer to send the XML document to- Throws:
IOException- If initialization fails
-
-
Method Details
-
getWriter
Returns the print writer used for the output of the XML document.- Returns:
- The print writer
-
setIndent
Defines whether the output should use indetation. Default istrue.- Parameters:
indent-trueif the output should use indentation,falseotherwise- Returns:
- The XML writer
-
setEncoding
Sets the character encoding of the output. Default isUTF-8.- Parameters:
encoding- The character encoding- Returns:
- The XML writer
-
omitXmlDeclaration
Defines whether the XML declaration should be omitted. Default isfalse.- Parameters:
omit-trueif the XML declaration should be omitted,falseotherwise- Returns:
- The XML writer
-
setDocumentLocator
Sets the document locator of the output.- Parameters:
locator- The document locator- Returns:
- The XML writer
-
open
Opens the XML document. This method is a shorthand foropenDocument().- Returns:
- The XML writer
- Throws:
IOException- If output fails
-
openDocument
Opens the XML document.- Returns:
- The XML writer
- Throws:
IOException- If output fails
-
open
Opens and returns a new XML element with the specified name.- Parameters:
name- The name of the XML element- Returns:
- The XML element
- Throws:
IOException- If output fails
-
open
Opens and returns a new XML element with the specified name.- Parameters:
localName- The local name of the XML elementname- The name of the XML element- Returns:
- The XML element
- Throws:
IOException- If output fails
-
open
Opens and returns a new XML element with the specified name.- Parameters:
uri- The URI of the XML elementlocalName- The local name of the XML elementname- The name of the XML element- Returns:
- The XML element
- Throws:
IOException- If output fails
-
open
Opens and returns a new XML element with the specified name and content.- Parameters:
name- The name of the XML elementcontent- The content of the XML elementcdata-trueif content should be in a CDATA block,falseotherwise- Returns:
- The XML element
- Throws:
IOException- If output fails
-
closeDocument
Closes the XML document after closing all open elements.- Throws:
IOException- If output fails
-
close
Closes the most recent open element.- Returns:
- The XML writer
- Throws:
IOException- If output fails
-
tidyUp
Closes all currently open elements.- Returns:
- The XML writer
- Throws:
IOException- If output fails
-