public class XMLWriter extends Object
XMLTagWriter tree.
Use like this:
XMLWriter wr = new XMLWriter(
new FileWriter( "test.xml" ),
new MyRootTagWriter()
);
// optionally define the DTD
wr.setDtd(
new String[]{
"faces-config" // name
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN", // public
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd" // system
}
);
// optionally set encoding
wr.setEncoding("UTF-8");
// write
try
{
wr.write( new MyRootDataObject() );
}
catch( XMLWriteException e )
{
// report some error
}
finally
{
try{ wr.close() } catch( IOException e ){}
}
| Constructor and Description |
|---|
XMLWriter(OutputStream os,
XMLTagWriter root)
Creates a new xml writer which wraps a exiting
OutputStream. |
XMLWriter(Writer wr,
XMLTagWriter root)
Creates a new xml writer which wraps a exiting
Writer. |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected XMLOutputter |
createXMLOutputter(Writer wr) |
protected void |
endDocument(XMLOutputter xout) |
String[] |
getDtd() |
String |
getEncoding() |
String |
getIndent() |
LineBreak |
getLineBreak() |
char |
getQuotation() |
XMLTagWriter |
getRootTagWriter() |
void |
setDtd(String[] dtd) |
void |
setEncoding(String encoding) |
void |
setIndent(String indent) |
void |
setLineBreak(LineBreak lineBreak) |
void |
setQuotation(char quotation) |
protected void |
startDocument(XMLOutputter xout) |
void |
write(Object o) |
public XMLWriter(Writer wr, XMLTagWriter root)
Writer.wr - the underlying writerroot - the root tag writer, must contain all sub tag writers of the documentpublic XMLWriter(OutputStream os, XMLTagWriter root)
OutputStream.os - the underlying output streamroot - the root tag writer, must contain all sub tag writers of the documentprotected XMLOutputter createXMLOutputter(Writer wr) throws UnsupportedEncodingException
UnsupportedEncodingExceptionpublic void write(Object o) throws XMLWriteException
XMLWriteExceptionprotected void startDocument(XMLOutputter xout)
throws XMLWriteException
XMLWriteExceptionprotected void endDocument(XMLOutputter xout)
public void close()
throws IllegalStateException,
IOException
IllegalStateExceptionIOExceptionpublic String[] getDtd()
public void setDtd(String[] dtd)
public String getEncoding()
public void setEncoding(String encoding)
public String getIndent()
public void setIndent(String indent)
public LineBreak getLineBreak()
public void setLineBreak(LineBreak lineBreak)
public char getQuotation()
public void setQuotation(char quotation)
public XMLTagWriter getRootTagWriter()
Copyright © 2017 SAP SE. All Rights Reserved.