APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.utils

public Class XmlWriter

extends Writer
Class Inheritance
Imports
java.io.IOException, .Writer

Builder style API for emitting XML.
 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);
 
Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
private String
public int
private boolean
private final Array<String>
private final Writer
Inherited from java.io.Writer:
lock

Constructor Summary

AccessConstructor and Description
public
XmlWriter(Writer writer)

Method Summary

Modifier and TypeMethod and Description
public XmlWriter
attribute(String name, Object value)

public void
close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Calls pop() for each remaining open element, if any, and closes the stream.

public XmlWriter
public XmlWriter
element(String name, Object text)

public void
flush()

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Flushes the stream.

private void
public XmlWriter
pop()

private boolean
public XmlWriter
text(Object text)

public void
write(char[] cbuf, int off, int len)

Implements abstract java.io.Writer.write.

Writes a portion of an array of characters.

Inherited from java.io.Writer:
appendappendappendnullWriterwritewritewritewrite

Field Detail

currentElementback to summary
private String currentElement
indentback to summary
public int indent
indentNextCloseback to summary
private boolean indentNextClose
stackback to summary
private final Array<String> stack
writerback to summary
private final Writer writer

Constructor Detail

XmlWriterback to summary
public XmlWriter(Writer writer)

Method Detail

attributeback to summary
public XmlWriter attribute(String name, Object value) throws IOException
closeback to summary
public void close() throws IOException

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Calls pop() for each remaining open element, if any, and closes the stream.

Exceptions
IOException:

Doc from java.io.Writer.close.

If an I/O error occurs

elementback to summary
public XmlWriter element(String name) throws IOException
elementback to summary
public XmlWriter element(String name, Object text) throws IOException
flushback to summary
public void flush() throws IOException

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Doc from java.io.Writer.flush.

Flushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Exceptions
IOException:
If an I/O error occurs
indentback to summary
private void indent() throws IOException
popback to summary
public XmlWriter pop() throws IOException
startElementContentback to summary
private boolean startElementContent() throws IOException
textback to summary
public XmlWriter text(Object text) throws IOException
writeback to summary
public void write(char[] cbuf, int off, int len) throws IOException

Implements abstract java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of an array of characters.

Exceptions
IOException:
If an I/O error occurs