public class SimpleXMLDoc
extends java.lang.Object
Convenience class to write out an XML document using a stream and a SAX parser. A stack is used to keep track of open and closed tag and on document close all tags are properly closed. It doesn’t guarantee the XML you might want or need, but it will be valid XML. The SAX Parser esures correct encoding of the tags and values
Modifier and Type | Class and Description |
---|---|
class |
SimpleXMLDoc.Element |
Constructor and Description |
---|
SimpleXMLDoc(java.io.OutputStream out)
Default constructor, creates empty document
|
Modifier and Type | Method and Description |
---|---|
SimpleXMLDoc |
addCdataElement(SimpleXMLDoc.Element element,
java.lang.String elementValue) |
SimpleXMLDoc |
addCdataElement(java.lang.String elementName,
java.lang.String elementValue) |
SimpleXMLDoc |
addComment(java.lang.String comment)
Adds a comment to the result.
|
SimpleXMLDoc |
addEmptyElement(SimpleXMLDoc.Element element) |
SimpleXMLDoc |
addEmptyElement(java.lang.String elementName) |
SimpleXMLDoc |
addNamespace(java.lang.String key,
java.lang.String uri)
Add namespace to a document
|
SimpleXMLDoc |
addSimpleElement(SimpleXMLDoc.Element element,
java.lang.String elementValue) |
SimpleXMLDoc |
addSimpleElement(java.lang.String elementName,
java.lang.String elementValue) |
void |
closeDocument()
Closes the document and ensures that all tags are closed
|
SimpleXMLDoc |
closeElement(int howMany) |
boolean |
closeElement(java.lang.String lastElementToClose) |
SimpleXMLDoc |
dateElement(SimpleXMLDoc.Element element,
java.util.Date date) |
SimpleXMLDoc |
dateElement(java.lang.String elementName,
java.util.Date date) |
SimpleXMLDoc.Element |
element(java.lang.String name) |
java.lang.String |
getDocTypePublic() |
java.lang.String |
getDocTypeSystem() |
java.lang.String |
getXmlStyleSheet() |
SimpleXMLDoc |
openElement(SimpleXMLDoc.Element element)
Starts a tag with a given tag element that contains name and attributes
|
SimpleXMLDoc |
openElement(java.lang.String elementName) |
SimpleXMLDoc |
setDocTypePublic(java.lang.String docTypePublic) |
SimpleXMLDoc |
setDocTypeSystem(java.lang.String docTypeSystem) |
SimpleXMLDoc |
setXmlStyleSheet(java.lang.String xmlStyleSheet) |
public SimpleXMLDoc(java.io.OutputStream out)
Default constructor, creates empty document
out
- Where the document goespublic SimpleXMLDoc addCdataElement(SimpleXMLDoc.Element element, java.lang.String elementValue)
element
- elementValue
- public SimpleXMLDoc addCdataElement(java.lang.String elementName, java.lang.String elementValue)
elementName
- elementValue
- public SimpleXMLDoc addComment(java.lang.String comment)
Adds a comment to the result. Comments are only written after the root element, so we cache them if necessary
comment
- The comment textpublic SimpleXMLDoc addEmptyElement(SimpleXMLDoc.Element element)
element
- The tag to addpublic SimpleXMLDoc addEmptyElement(java.lang.String elementName)
elementName
- public SimpleXMLDoc addNamespace(java.lang.String key, java.lang.String uri)
Add namespace to a document
key
- Namespace abbreviation without :uri
- Namespace URLpublic SimpleXMLDoc addSimpleElement(SimpleXMLDoc.Element element, java.lang.String elementValue)
element
- elementValue
- public SimpleXMLDoc addSimpleElement(java.lang.String elementName, java.lang.String elementValue)
elementName
- elementValue
- public void closeDocument()
Closes the document and ensures that all tags are closed
public SimpleXMLDoc closeElement(int howMany)
howMany
- public boolean closeElement(java.lang.String lastElementToClose)
lastElementToClose
- public SimpleXMLDoc dateElement(SimpleXMLDoc.Element element, java.util.Date date)
element
- date
- public SimpleXMLDoc dateElement(java.lang.String elementName, java.util.Date date)
elementName
- date
- public SimpleXMLDoc.Element element(java.lang.String name)
name
- public java.lang.String getDocTypePublic()
public java.lang.String getDocTypeSystem()
public java.lang.String getXmlStyleSheet()
public SimpleXMLDoc openElement(SimpleXMLDoc.Element element)
Starts a tag with a given tag element that contains name and attributes
element
- public SimpleXMLDoc openElement(java.lang.String elementName)
elementName
- public SimpleXMLDoc setDocTypePublic(java.lang.String docTypePublic)
docTypePublic
- public SimpleXMLDoc setDocTypeSystem(java.lang.String docTypeSystem)
docTypeSystem
- public SimpleXMLDoc setXmlStyleSheet(java.lang.String xmlStyleSheet)
xmlStyleSheet
-