Save This Page
Home » dom4j-1.6.1 » org.dom4j.io » [javadoc | source]
org.dom4j.io
public class: XMLWriter [javadoc | source]
java.lang.Object
   org.xml.sax.helpers.XMLFilterImpl
      org.dom4j.io.XMLWriter

All Implemented Interfaces:
    LexicalHandler, ErrorHandler, EntityResolver, XMLFilter, ContentHandler, DTDHandler

Direct Known Subclasses:
    HTMLWriter

XMLWriter takes a DOM4J tree and formats it to a stream as XML. It can also take SAX events too so can be used by SAX clients as this object implements the org.xml.sax.ContentHandler and LexicalHandler interfaces. as well. This formatter performs typical document formatting. The XML declaration and processing instructions are always on their own lines. An OutputFormat object can be used to define how whitespace is handled when printing and allows various configuration options, such as to allow suppression of the XML declaration, the encoding declaration or whether empty documents are collapsed.

There are write(...) methods to print any of the standard DOM4J classes, including Document and Element, to either a Writer or an OutputStream. Warning: using your own Writer may cause the writer's preferred character encoding to be ignored. If you use encodings other than UTF8, we recommend using the method that takes an OutputStream instead.

Field Summary
protected static final  String[] LEXICAL_HANDLER_NAMES     
protected static final  OutputFormat DEFAULT_FORMAT     
protected  int lastOutputNodeType    Stores the last type of node written so algorithms can refer to the previous node type 
protected  boolean preserve    Stores the xml:space attribute value of preserve for whitespace flag 
protected  Writer writer    The Writer used to output to 
Constructor:
 public XMLWriter() 
 public XMLWriter(Writer writer) 
 public XMLWriter(OutputStream out) throws UnsupportedEncodingException 
 public XMLWriter(OutputFormat format) throws UnsupportedEncodingException 
 public XMLWriter(Writer writer,
    OutputFormat format) 
 public XMLWriter(OutputStream out,
    OutputFormat format) throws UnsupportedEncodingException 
Method from org.dom4j.io.XMLWriter Summary:
characters,   close,   comment,   createWriter,   defaultMaximumAllowedCharacter,   endCDATA,   endDTD,   endDocument,   endElement,   endEntity,   endPrefixMapping,   escapeAttributeEntities,   escapeElementEntities,   flush,   getLexicalHandler,   getMaximumAllowedCharacter,   getOutputFormat,   getProperty,   handleException,   ignorableWhitespace,   indent,   installLexicalHandler,   isElementSpacePreserved,   isEscapeText,   isExpandEmptyElements,   isNamespaceDeclaration,   notationDecl,   parse,   println,   processingInstruction,   resolveEntityRefs,   setDocumentLocator,   setEscapeText,   setIndentLevel,   setLexicalHandler,   setMaximumAllowedCharacter,   setOutputStream,   setProperty,   setResolveEntityRefs,   setWriter,   shouldEncodeChar,   startCDATA,   startDTD,   startDocument,   startElement,   startEntity,   startPrefixMapping,   unparsedEntityDecl,   write,   write,   write,   write,   write,   write,   write,   write,   write,   write,   write,   write,   write,   writeAttribute,   writeAttribute,   writeAttributes,   writeAttributes,   writeCDATA,   writeClose,   writeClose,   writeComment,   writeDeclaration,   writeDocType,   writeDocType,   writeElement,   writeElementContent,   writeEmptyElementClose,   writeEntity,   writeEntityRef,   writeEscapeAttributeEntities,   writeNamespace,   writeNamespace,   writeNamespaces,   writeNode,   writeNodeText,   writeOpen,   writePrintln,   writeProcessingInstruction,   writeString
Methods from org.xml.sax.helpers.XMLFilterImpl:
characters,   endDocument,   endElement,   endPrefixMapping,   error,   fatalError,   getContentHandler,   getDTDHandler,   getEntityResolver,   getErrorHandler,   getFeature,   getParent,   getProperty,   ignorableWhitespace,   notationDecl,   parse,   parse,   processingInstruction,   resolveEntity,   setContentHandler,   setDTDHandler,   setDocumentLocator,   setEntityResolver,   setErrorHandler,   setFeature,   setParent,   setProperty,   skippedEntity,   startDocument,   startElement,   startPrefixMapping,   unparsedEntityDecl,   warning
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.dom4j.io.XMLWriter Detail:
 public  void characters(char[] ch,
    int start,
    int length) throws SAXException 
 public  void close() throws IOException 
    Closes the underlying Writer
 public  void comment(char[] ch,
    int start,
    int length) throws SAXException 
 protected Writer createWriter(OutputStream outStream,
    String encoding) throws UnsupportedEncodingException 
    Get an OutputStreamWriter, use preferred encoding.
 protected int defaultMaximumAllowedCharacter() 
    Returns the maximum allowed character code that should be allowed unescaped which defaults to 127 in US-ASCII (7 bit) or 255 in ISO- (8 bit).
 public  void endCDATA() throws SAXException 
 public  void endDTD() throws SAXException 
 public  void endDocument() throws SAXException 
 public  void endElement(String namespaceURI,
    String localName,
    String qName) throws SAXException 
 public  void endEntity(String name) throws SAXException 
 public  void endPrefixMapping(String prefix) throws SAXException 
 protected String escapeAttributeEntities(String text) 
    This will take the pre-defined entities in XML 1.0 and convert their character representation to the appropriate entity reference, suitable for XML attributes.
 protected String escapeElementEntities(String text) 
    This will take the pre-defined entities in XML 1.0 and convert their character representation to the appropriate entity reference, suitable for XML attributes.
 public  void flush() throws IOException 
    Flushes the underlying Writer
 public LexicalHandler getLexicalHandler() 
 public int getMaximumAllowedCharacter() 
    Returns the maximum allowed character code that should be allowed unescaped which defaults to 127 in US-ASCII (7 bit) or 255 in ISO- (8 bit).
 protected OutputFormat getOutputFormat() 
    Lets subclasses get at the current format object, so they can call setTrimText, setNewLines, etc. Put in to support the HTMLWriter, in the way that it pushes the current newline/trim state onto a stack and overrides the state within preformatted tags.
 public Object getProperty(String name) throws SAXNotSupportedException, SAXNotRecognizedException 
 protected  void handleException(IOException e) throws SAXException 
 public  void ignorableWhitespace(char[] ch,
    int start,
    int length) throws SAXException 
 protected  void indent() throws IOException 
 protected  void installLexicalHandler() 
 protected final boolean isElementSpacePreserved(Element element) 
    Determines if element is a special case of XML elements where it contains an xml:space attribute of "preserve". If it does, then retain whitespace.
 public boolean isEscapeText() 
    DOCUMENT ME!
 protected boolean isExpandEmptyElements() 
 protected boolean isNamespaceDeclaration(Namespace ns) 
 public  void notationDecl(String name,
    String publicID,
    String systemID) throws SAXException 
 public  void parse(InputSource source) throws IOException, SAXException 
 public  void println() throws IOException 
    Writes the new line text to the underlying Writer
 public  void processingInstruction(String target,
    String data) throws SAXException 
 public boolean resolveEntityRefs() 
 public  void setDocumentLocator(Locator locator) 
 public  void setEscapeText(boolean escapeText) 
    Sets whether text output should be escaped or not. This is enabled by default. It could be disabled if the output format is textual, like in XSLT where we can have xml, html or text output.
 public  void setIndentLevel(int indentLevel) 
    Set the initial indentation level. This can be used to output a document (or, more likely, an element) starting at a given indent level, so it's not always flush against the left margin. Default: 0
 public  void setLexicalHandler(LexicalHandler handler) 
 public  void setMaximumAllowedCharacter(int maximumAllowedCharacter) 
    Sets the maximum allowed character code that should be allowed unescaped such as 127 in US-ASCII (7 bit) or 255 in ISO- (8 bit) or -1 to not escape any characters (other than the special XML characters like < > &) If this is not explicitly set then it is defaulted from the encoding.
 public  void setOutputStream(OutputStream out) throws UnsupportedEncodingException 
 public  void setProperty(String name,
    Object value) throws SAXNotSupportedException, SAXNotRecognizedException 
 public  void setResolveEntityRefs(boolean resolve) 
 public  void setWriter(Writer writer) 
 protected boolean shouldEncodeChar(char c) 
    Should the given character be escaped. This depends on the encoding of the document.
 public  void startCDATA() throws SAXException 
 public  void startDTD(String name,
    String publicID,
    String systemID) throws SAXException 
 public  void startDocument() throws SAXException 
 public  void startElement(String namespaceURI,
    String localName,
    String qName,
    Attributes attributes) throws SAXException 
 public  void startEntity(String name) throws SAXException 
 public  void startPrefixMapping(String prefix,
    String uri) throws SAXException 
 public  void unparsedEntityDecl(String name,
    String publicID,
    String systemID,
    String notationName) throws SAXException 
 public  void write(Attribute attribute) throws IOException 
 public  void write(Document doc) throws IOException 

    This will print the Document to the current Writer.

    Warning: using your own Writer may cause the writer's preferred character encoding to be ignored. If you use encodings other than UTF8, we recommend using the method that takes an OutputStream instead.

    Note: as with all Writers, you may need to flush() yours after this method returns.

 public  void write(Element element) throws IOException 

    Writes the Element , including its Attribute s, and its value, and all its content (child nodes) to the current Writer.

 public  void write(CDATA cdata) throws IOException 
 public  void write(Comment comment) throws IOException 
 public  void write(DocumentType docType) throws IOException 
 public  void write(Entity entity) throws IOException 
 public  void write(Namespace namespace) throws IOException 
 public  void write(ProcessingInstruction processingInstruction) throws IOException 
 public  void write(String text) throws IOException 

    Print out a String , Perfoms the necessary entity escaping and whitespace stripping.

 public  void write(Text text) throws IOException 
    Writes the given Text .
 public  void write(Node node) throws IOException 
    Writes the given Node .
 public  void write(Object object) throws IOException 
    Writes the given object which should be a String, a Node or a List of Nodes.
 protected  void writeAttribute(Attribute attribute) throws IOException 
 protected  void writeAttribute(Attributes attributes,
    int index) throws IOException 
 protected  void writeAttributes(Element element) throws IOException 
    Writes the attributes of the given element
 protected  void writeAttributes(Attributes attributes) throws IOException 
 protected  void writeCDATA(String text) throws IOException 
 public  void writeClose(Element element) throws IOException 

    Writes the closing tag of an Element

 protected  void writeClose(String qualifiedName) throws IOException 
 protected  void writeComment(String text) throws IOException 
 protected  void writeDeclaration() throws IOException 

    This will write the declaration to the given Writer. Assumes XML version 1.0 since we don't directly know.

 protected  void writeDocType(DocumentType docType) throws IOException 
 protected  void writeDocType(String name,
    String publicID,
    String systemID) throws IOException 
 protected  void writeElement(Element element) throws IOException 
 protected  void writeElementContent(Element element) throws IOException 
    Outputs the content of the given element. If whitespace trimming is enabled then all adjacent text nodes are appended together before the whitespace trimming occurs to avoid problems with multiple text nodes being created due to text content that spans parser buffers in a SAX parser.
 protected  void writeEmptyElementClose(String qualifiedName) throws IOException 
 protected  void writeEntity(Entity entity) throws IOException 
 protected  void writeEntityRef(String name) throws IOException 
 protected  void writeEscapeAttributeEntities(String txt) throws IOException 
 protected  void writeNamespace(Namespace namespace) throws IOException 
 protected  void writeNamespace(String prefix,
    String uri) throws IOException 
    Writes the SAX namepsaces
 protected  void writeNamespaces() throws IOException 
    Writes the SAX namepsaces
 protected  void writeNode(Node node) throws IOException 
 protected  void writeNodeText(Node node) throws IOException 
    This method is used to write out Nodes that contain text and still allow for xml:space to be handled properly.
 public  void writeOpen(Element element) throws IOException 

    Writes the opening tag of an Element , including its Attribute s but without its content.

 protected  void writePrintln() throws IOException 

    This will print a new line only if the newlines flag was set to true

 protected  void writeProcessingInstruction(ProcessingInstruction pi) throws IOException 
 protected  void writeString(String text) throws IOException