Interface XMLWriter
-
- All Known Implementing Classes:
PrettyPrintXMLWriter
public interface XMLWriter
Interface 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 void
addAttribute(java.lang.String key, java.lang.String value)
Add a XML attribute to the current XML Element.void
endElement()
End the previously opened element.void
setDocType(java.lang.String docType)
Sets the DOCTYPE of the document.void
setEncoding(java.lang.String encoding)
Sets the encoding of the document.void
startElement(java.lang.String name)
Start an XML Element tag.void
writeMarkup(java.lang.String text)
Add preformatted markup to the current element tag.void
writeText(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.IOException
Start 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.IOException
Add 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.IOException
Add 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.IOException
Add 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.IOException
End the previously opened element.- Throws:
java.io.IOException
- if ending the element fails.- See Also:
startElement(String)
-
-