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
Modifier and TypeMethodDescriptionvoid
addAttribute
(String key, String value) Add a XML attribute to the current XML Element.void
End the previously opened element.void
setDocType
(String docType) Sets the DOCTYPE of the document.void
setEncoding
(String encoding) Sets the encoding of the document.void
startElement
(String name) Start an XML Element tag.void
writeMarkup
(String text) Add preformatted markup to the current element tag.void
Add text to the current element tag.
-
Method Details
-
setEncoding
Sets the encoding of the document. If not set, UTF-8 is used.- Parameters:
encoding
- the encoding- Throws:
IllegalStateException
- if the generation of the document has already started
-
setDocType
Sets the DOCTYPE of the document.- Parameters:
docType
- the docType- Throws:
IllegalStateException
- if the generation of the document has already started
-
startElement
Start an XML Element tag.- Parameters:
name
- the name of the tag- Throws:
IOException
- if starting the element fails
-
addAttribute
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:
IllegalStateException
- if no element tag is currently in processIOException
- if adding the attribute fails.
-
writeText
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:
IllegalStateException
- if no element tag got started yetIOException
- if writing the text fails.
-
writeMarkup
Add preformatted markup to the current element tag.- Parameters:
text
- the text which should be written- Throws:
IllegalStateException
- if no element tag is started yetIOException
- if writing the markup fails
-
endElement
End the previously opened element.- Throws:
IOException
- if ending the element fails.- See Also:
-