Package com.yahoo.document.serialization
Class XmlStream
- java.lang.Object
-
- com.yahoo.document.serialization.XmlStream
-
public class XmlStream extends Object
Class for writing XML in a simplified way.Give a writer for it to write the XML directly to. If none is given a StringWriter is used so you can call toString() on the class to get the XML.
You build XML by calling beginTag(name), addAttribute(id, value), endTag(). Remember to close all your tags, or you'll get an exception when calling toString(). If writing directly to a writer, call isFinalized to verify that all tags have been closed.
The XML escaping tools only give an interface for escape from and to a string value. Thus writing of all data here is also just available through strings.
- Author:
- Haakon Humberset
-
-
Constructor Summary
Constructors Constructor Description XmlStream()
Create an XmlStream writing to a StringWriter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAttribute(String key, Object value)
Add a new XML attribute to the last tag started.void
addContent(String content)
Add content to the last tag.void
beginTag(String name)
Add a new XML tag with the given name.void
endTag()
Ends the last tag created.boolean
isFinalized()
Check if all tags have been properly closed.void
setIndent(String indent)
Set an indent to use for pretty printing of XML.String
toString()
-
-
-
Method Detail
-
setIndent
public void setIndent(String indent)
Set an indent to use for pretty printing of XML. Default is no indent.- Parameters:
indent
- the initial indentation
-
isFinalized
public boolean isFinalized()
Check if all tags have been properly closed.- Returns:
- true if all tags are closed
-
beginTag
public void beginTag(String name)
Add a new XML tag with the given name.- Parameters:
name
- the tag name
-
addAttribute
public void addAttribute(String key, Object value)
Add a new XML attribute to the last tag started. The tag cannot already have had content added to it, or been ended. If a null value is added, the attribute will be skipped.- Parameters:
key
- the attribute namevalue
- the attribute value
-
addContent
public void addContent(String content)
Add content to the last tag.- Parameters:
content
- the content to add to the last tag
-
endTag
public void endTag()
Ends the last tag created.
-
-