XML for Java Compatibility API 2.0.15

com.ibm.xml.parser
Class ToXMLStringVisitor

java.lang.Object
  |
  +--com.ibm.xml.parser.NOOPVisitor
        |
        +--com.ibm.xml.parser.ToXMLStringVisitor
Direct Known Subclasses:
FormatPrintVisitor, HTMLPrintVisitor

public class ToXMLStringVisitor
extends NOOPVisitor
implements Visitor

ToXMLStringVisitor implements the Visitor interface in the visitor design pattern for the purpose of a toString operation on the various DOM- and XML4J-defined Nodes as the document object tree is traversed. The returned string will be in XML format.

The following sample code uses the ToXMLStringVisitor on a hierarchy of nodes:


 Visitor visitor = new ToXMLStringVisitor(stringWriter, encoding);
 new NonRecursivePreorderTreeTraversal(visitor).traverse(this);

 

Version:
Revision: 93 1.3 src/com/ibm/xml/parser/ToXMLStringVisitor.java, parser, xml4j2, xml4j2_0_15
See Also:
Visitor, NOOPVisitor, TreeTraversal, NonRecursivePreorderTreeTraversal

Field Summary
protected  java.lang.String encoding
           
protected  boolean isPrintNonSpecifiedAttributes
           
protected  java.io.Writer writer
           
 
Constructor Summary
ToXMLStringVisitor(java.io.Writer writer)
          Constructor for default encoding.
ToXMLStringVisitor(java.io.Writer writer, java.lang.String encoding)
          Constructor for customized encoding.
 
Method Summary
 boolean getPrintNonSpecifiedAttributes()
          Returns whether this prints non-specified default attributes appended by DTD.
 void setPrintNonSpecifiedAttributes(boolean print)
          Sets whether this prints non-specified default attributes appended by DTD.
 void visitAttDefPre(AttDef attDef)
          Creates a string representation of the specified attDef Node in XML format.
 void visitAttlistPre(Attlist attlist)
          Creates a string representation of the specified attlist Node and any associated AttDefs in XML format.
 void visitAttributePre(TXAttribute attribute)
          Creates a string representation of the specified attribute Node in XML format.
 void visitCommentPre(TXComment comment)
          Creates a string representation of the specified comment Node in XML format.
 void visitDocumentPost(TXDocument document)
          Flush the writer.
 void visitDocumentPre(TXDocument document)
          Creates a string representation of the specified document Node in XML format.
 void visitDTDPost(DTD dtd)
          Creates a string representation of the specified dtd Node, and optionally its internal DTD subset, in XML format.
 void visitDTDPre(DTD dtd)
          Creates a string representation of the specified dtd Node, and optionally its internal DTD subset, in XML format.
 void visitElementDeclPre(ElementDecl elementDecl)
          Creates a string representation of the specified elementDecl Node in XML format.
 void visitElementPost(TXElement element)
          Creates a string representation of the end of the specified element Node in XML format.
 void visitElementPre(TXElement element)
          Creates a string representation of the start of the specified element Node and its associated attributes in XML format.
 void visitEntityDeclPre(EntityDecl entityDecl)
          Creates a string representation of the specified entityDecl Node in XML format.
 void visitGeneralReferencePre(GeneralReference generalReference)
          Creates a string representation of the specified generalReference Node in XML format.
 void visitNotationPre(TXNotation notation)
          Creates a string representation of the specified notation Node in XML format.
 void visitPIPre(TXPI pi)
          Creates a string representation of the specified pi Node in XML format.
 void visitPseudoNodePre(PseudoNode pseudoNode)
          Creates a string representation of the specified pseudoNode Node in XML format.
 void visitTextPre(TXText text)
          Creates a string representation of the specified text Node in XML format.
 
Methods inherited from class com.ibm.xml.parser.NOOPVisitor
visitAttDefPost, visitAttlistPost, visitAttributePost, visitCommentPost, visitDocumentFragmentPost, visitDocumentFragmentPre, visitElementDeclPost, visitEntityDeclPost, visitGeneralReferencePost, visitNotationPost, visitPIPost, visitPseudoNodePost, visitTextPost
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

writer

protected java.io.Writer writer

encoding

protected java.lang.String encoding

isPrintNonSpecifiedAttributes

protected boolean isPrintNonSpecifiedAttributes
Constructor Detail

ToXMLStringVisitor

public ToXMLStringVisitor(java.io.Writer writer,
                          java.lang.String encoding)
Constructor for customized encoding.
Parameters:
writer - The character output stream to use.
encoding - Java character encoding in use by writer.

ToXMLStringVisitor

public ToXMLStringVisitor(java.io.Writer writer)
Constructor for default encoding.
Parameters:
writer - The character output stream to use.
Method Detail

setPrintNonSpecifiedAttributes

public void setPrintNonSpecifiedAttributes(boolean print)
Sets whether this prints non-specified default attributes appended by DTD.

By default, non-specified attributes are printed.

See Also:
TXAttribute.getSpecified()

getPrintNonSpecifiedAttributes

public boolean getPrintNonSpecifiedAttributes()
Returns whether this prints non-specified default attributes appended by DTD.

visitDocumentPre

public void visitDocumentPre(TXDocument document)
                      throws java.lang.Exception
Creates a string representation of the specified document Node in XML format.
Specified by:
visitDocumentPre in interface Visitor
Parameters:
document - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitDocumentPre in class NOOPVisitor
See Also:
TXDocument

visitDocumentPost

public void visitDocumentPost(TXDocument document)
                       throws java.lang.Exception
Flush the writer.
Specified by:
visitDocumentPost in interface Visitor
Parameters:
document - CURRENTLY NOT IMPLEMENTED.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitDocumentPost in class NOOPVisitor
See Also:
TXDocument

visitElementPre

public void visitElementPre(TXElement element)
                     throws java.lang.Exception
Creates a string representation of the start of the specified element Node and its associated attributes in XML format.
Specified by:
visitElementPre in interface Visitor
Parameters:
element - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitElementPre in class NOOPVisitor
See Also:
TXElement

visitElementPost

public void visitElementPost(TXElement element)
                      throws java.lang.Exception
Creates a string representation of the end of the specified element Node in XML format.
Specified by:
visitElementPost in interface Visitor
Parameters:
element - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitElementPost in class NOOPVisitor
See Also:
TXElement

visitAttributePre

public void visitAttributePre(TXAttribute attribute)
                       throws java.lang.Exception
Creates a string representation of the specified attribute Node in XML format.

Note that TXAttribute Nodes are not parsed into the document object hierarchy by the XML4J parser; attributes exist as part of a TXElement Node.

Specified by:
visitAttributePre in interface Visitor
Parameters:
attribute - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
ToNextSiblingTraversalException - Always thrown.
Overrides:
visitAttributePre in class NOOPVisitor
See Also:
TXAttribute

visitPIPre

public void visitPIPre(TXPI pi)
                throws java.lang.Exception
Creates a string representation of the specified pi Node in XML format.
Specified by:
visitPIPre in interface Visitor
Parameters:
pi - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitPIPre in class NOOPVisitor
See Also:
TXPI

visitCommentPre

public void visitCommentPre(TXComment comment)
                     throws java.lang.Exception
Creates a string representation of the specified comment Node in XML format.
Specified by:
visitCommentPre in interface Visitor
Parameters:
comment - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitCommentPre in class NOOPVisitor
See Also:
TXComment

visitTextPre

public void visitTextPre(TXText text)
                  throws java.lang.Exception
Creates a string representation of the specified text Node in XML format. CDATASections are respected.
Specified by:
visitTextPre in interface Visitor
Parameters:
text - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitTextPre in class NOOPVisitor
See Also:
TXText

visitDTDPre

public void visitDTDPre(DTD dtd)
                 throws java.lang.Exception
Creates a string representation of the specified dtd Node, and optionally its internal DTD subset, in XML format. The internal DTD subset will be included based on the value of isPrintInternalDTD().
Specified by:
visitDTDPre in interface Visitor
Parameters:
dtd - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
ToNextSiblingTraversalException - Thrown if isPrintInternalDTD() is false.
Overrides:
visitDTDPre in class NOOPVisitor
See Also:
DTD.isPrintInternalDTD(), DTD

visitDTDPost

public void visitDTDPost(DTD dtd)
                  throws java.lang.Exception
Creates a string representation of the specified dtd Node, and optionally its internal DTD subset, in XML format. The internal DTD subset will be included based on the value of isPrintInternalDTD().
Specified by:
visitDTDPost in interface Visitor
Parameters:
dtd - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitDTDPost in class NOOPVisitor
See Also:
DTD.isPrintInternalDTD(), DTD

visitElementDeclPre

public void visitElementDeclPre(ElementDecl elementDecl)
                         throws java.lang.Exception
Creates a string representation of the specified elementDecl Node in XML format.
Specified by:
visitElementDeclPre in interface Visitor
Parameters:
elementDecl - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitElementDeclPre in class NOOPVisitor
See Also:
ElementDecl

visitAttlistPre

public void visitAttlistPre(Attlist attlist)
                     throws java.lang.Exception
Creates a string representation of the specified attlist Node and any associated AttDefs in XML format.
Specified by:
visitAttlistPre in interface Visitor
Parameters:
attlist - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitAttlistPre in class NOOPVisitor
See Also:
Attlist

visitAttDefPre

public void visitAttDefPre(AttDef attDef)
                    throws java.lang.Exception
Creates a string representation of the specified attDef Node in XML format.
Specified by:
visitAttDefPre in interface Visitor
Parameters:
attDef - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitAttDefPre in class NOOPVisitor
See Also:
AttDef

visitEntityDeclPre

public void visitEntityDeclPre(EntityDecl entityDecl)
                        throws java.lang.Exception
Creates a string representation of the specified entityDecl Node in XML format.
Specified by:
visitEntityDeclPre in interface Visitor
Parameters:
entity - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitEntityDeclPre in class NOOPVisitor
See Also:
EntityDecl

visitNotationPre

public void visitNotationPre(TXNotation notation)
                      throws java.lang.Exception
Creates a string representation of the specified notation Node in XML format.
Specified by:
visitNotationPre in interface Visitor
Parameters:
notation - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitNotationPre in class NOOPVisitor
See Also:
TXNotation

visitGeneralReferencePre

public void visitGeneralReferencePre(GeneralReference generalReference)
                              throws java.lang.Exception
Creates a string representation of the specified generalReference Node in XML format.
Specified by:
visitGeneralReferencePre in interface Visitor
Parameters:
generalReference - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
ToNextSiblingTraversalException - Alway thrown.
Overrides:
visitGeneralReferencePre in class NOOPVisitor
See Also:
GeneralReference

visitPseudoNodePre

public void visitPseudoNodePre(PseudoNode pseudoNode)
                        throws java.lang.Exception
Creates a string representation of the specified pseudoNode Node in XML format.
Specified by:
visitPseudoNodePre in interface Visitor
Parameters:
pseudoNode - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitPseudoNodePre in class NOOPVisitor
See Also:
PseudoNode

XML for Java Compatibility API 2.0.15