public class XmlWriter extends Writer
StringWriter writer = new StringWriter();
XmlWriter xml = new XmlWriter(writer);
xml.element("meow")
.attribute("moo", "cow")
.element("child")
.attribute("moo", "cow")
.element("child")
.attribute("moo", "cow")
.text("XML is like violence. If it doesn't solve your problem, you're not using enough of it.")
.pop()
.pop()
.pop();
System.out.println(writer);
| Modifier and Type | Field and Description |
|---|---|
int |
indent |
| Modifier and Type | Method and Description |
|---|---|
XmlWriter |
attribute(String name,
Object value) |
void |
close()
Calls
pop() for each remaining open element, if any, and closes the stream. |
XmlWriter |
element(String name) |
XmlWriter |
element(String name,
Object text) |
void |
flush() |
XmlWriter |
pop() |
XmlWriter |
text(Object text) |
void |
write(char[] cbuf,
int off,
int len) |
public XmlWriter(Writer writer)
public XmlWriter element(String name) throws IOException
IOExceptionpublic XmlWriter element(String name, Object text) throws IOException
IOExceptionpublic XmlWriter attribute(String name, Object value) throws IOException
IOExceptionpublic XmlWriter text(Object text) throws IOException
IOExceptionpublic XmlWriter pop() throws IOException
IOExceptionpublic void close()
throws IOException
pop() for each remaining open element, if any, and closes the stream.close in interface Closeableclose in interface AutoCloseableclose in class WriterIOExceptionpublic void write(char[] cbuf,
int off,
int len)
throws IOException
write in class WriterIOExceptionpublic void flush()
throws IOException
flush in interface Flushableflush in class WriterIOExceptionCopyright © 2021. All rights reserved.