All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----org.xmlmiddleware.xmlutils.XMLWriter
This is used as the base class for classes such as MapSerializer, which write things out as XML.
If you want to use a specific encoding, the Writer must be an OutputStreamWriter or a subclass of an OutputStreamWriter. For example, you might use the following code to write to the list.xml file with the Shift_JIS encoding:
// Construct the FileOutputStream.
OutputStream out = new FileOutputStream("list.xml");
// Construct the OutputStreamWriter with the Shift_JIS encoding. This may
// throw an UnsupportedEncodingException.
Writer writer = new OutputStreamWriter(out, "Shift_JIS");
// Construct the XMLWriter.
XMLWriter xmlWriter = new XMLWriter(writer);
// Write to the XMLWriter.
...
// Close the file.
writer.close();
If you want to use the default encoding, you can just use a FileWriter. However, no encoding declaration will be written in the XML declaration. For example:
// Construct a new FileWriter.
Writer writer = new FileWriter("list.xml");
// Construct the XMLWriter.
XMLWriter xmlWriter = new XMLWriter(writer);
// Write to the XMLWriter.
...
// Close the file.
writer.close();
WARNING: This class does not check that you write a valid XML document. For example, you could write two DOCTYPE statements or improperly nested elements.
public String attrs[]
public String values[]
public XMLWriter()
public XMLWriter(Writer writer)
public Writer getWriter()
public void setWriter(Writer writer)
This method should not be called after you have started writing the document.
public void setPrettyPrinting(boolean pretty,
int increment)
This method should not be called after you have started writing the document.
public void writeXMLDecl() throws IOException
An encoding declaration will be written only if the Writer is an OutputStreamWriter or a subclass of OutputStreamWriter.
public void writeXMLDecl(boolean standalone) throws IOException
An encoding declaration will be written only if the Writer is an OutputStreamWriter or a subclass of OutputStreamWriter.
public void writeDOCTYPE(String root,
String systemID,
String publicID) throws IOException
Internal subsets are not supported.
public void writeElementStart(String name,
int numAttrs,
boolean empty) throws IOException
public void writeElementEnd(String name) throws IOException
public void writeCharacters(String characters) throws IOException
public void writeCharacters(char characters[],
int start,
int length) throws IOException
public void allocateAttrs(int size)
All Packages Class Hierarchy This Package Previous Next Index