Interface XMLWriter
-
- All Known Implementing Classes:
PrettyPrintXMLWriter
public interface XMLWriterInterface for tools writing XML files. XMLWriters are not thread safe and must not be accessed concurrently.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddAttribute(java.lang.String key, java.lang.String value)Add a XML attribute to the current XML Element.voidendElement()End the previously opened element.voidsetDocType(java.lang.String docType)Sets the DOCTYPE of the document.voidsetEncoding(java.lang.String encoding)Sets the encoding of the document.voidstartElement(java.lang.String name)Start an XML Element tag.voidwriteMarkup(java.lang.String text)Add preformatted markup to the current element tag.voidwriteText(java.lang.String text)Add text to the current element tag.
-
-
-
Method Detail
-
setEncoding
void setEncoding(java.lang.String encoding)
Sets the encoding of the document. If not set, UTF-8 is used.- Parameters:
encoding- the encoding- Throws:
java.lang.IllegalStateException- if the generation of the document has already started
-
setDocType
void setDocType(java.lang.String docType)
Sets the DOCTYPE of the document.- Parameters:
docType- the docType- Throws:
java.lang.IllegalStateException- if the generation of the document has already started
-
startElement
void startElement(java.lang.String name) throws java.io.IOExceptionStart an XML Element tag.- Parameters:
name- the name of the tag- Throws:
java.io.IOException- if starting the element fails
-
addAttribute
void addAttribute(java.lang.String key, java.lang.String value) throws java.io.IOExceptionAdd a XML attribute to the current XML Element. This method must get called immediately afterstartElement(String).- Parameters:
key- The key of the attribute.value- The value of the attribute.- Throws:
java.lang.IllegalStateException- if no element tag is currently in processjava.io.IOException- if adding the attribute fails.
-
writeText
void writeText(java.lang.String text) throws java.io.IOExceptionAdd text to the current element tag. This performs XML escaping to guarantee well-formed content.- Parameters:
text- The text which should be written.- Throws:
java.lang.IllegalStateException- if no element tag got started yetjava.io.IOException- if writing the text fails.
-
writeMarkup
void writeMarkup(java.lang.String text) throws java.io.IOExceptionAdd preformatted markup to the current element tag.- Parameters:
text- the text which should be written- Throws:
java.lang.IllegalStateException- if no element tag is started yetjava.io.IOException- if writing the markup fails
-
endElement
void endElement() throws java.io.IOExceptionEnd the previously opened element.- Throws:
java.io.IOException- if ending the element fails.- See Also:
startElement(String)
-
-