Class XMLWriter

java.lang.Object
org.eclipse.rdf4j.common.xml.XMLWriter

public class XMLWriter extends Object
A utility class offering convenience methods for writing XML. This class takes care of character escaping, identation, etc. This class does not verify that the written data is legal XML. It is the callers responsibility to make sure that elements are properly nested, etc.

Example:

To write the following XML:

 <?xml version='1.0' encoding='UTF-8'?>
 <xml-doc>
 <foo a="1" b="2&amp;3"/>
 <bar>Hello World!</bar>
 </xml-doc>
 

One can use the following code:

 XMLWriter xmlWriter = new XMLWriter(myWriter);
 xmlWriter.setPrettyPrint(true);

 xmlWriter.startDocument();
 xmlWriter.startTag("xml-doc");

 xmlWriter.setAttribute("a", 1);
 xmlWriter.setAttribute("b", "2&3");
 xmlWriter.simpleTag("foo");

 xmlWriter.textTag("bar", "Hello World!");

 xmlWriter.endTag("xml-doc");
 xmlWriter.endDocument();