th.co.edge.jseq.util
Class XMLUtil.NodePrinter

java.lang.Object
  extended by th.co.edge.jseq.util.XMLUtil.NodePrinter
All Implemented Interfaces:
XMLUtil.Visitor
Enclosing class:
XMLUtil

public static class XMLUtil.NodePrinter
extends java.lang.Object
implements XMLUtil.Visitor

An implementation of Visitor that creates a string representation of a Node and its children, or in other words, to a (part of) an XML document.

To use this class, create a new NodePrinter instance, call XMLUtil.traverse using it, and then call the toString method on the NodePrinter.


Constructor Summary
XMLUtil.NodePrinter(boolean prettyPrint)
          Creates a new NodePrinter.
 
Method Summary
 void afterVisit(org.w3c.dom.Node node)
          For an element node, adds the end tag for the given Node to the string representation of the XML document, if necessary.
 java.lang.String toString()
          Returns a string representation of the Node that has been traversed using this NodePrinter, or the empty string if the Node has not yet been traversed.
 boolean visit(org.w3c.dom.Node node)
          Adds the string representation appropriate at the beginning of the given Node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XMLUtil.NodePrinter

public XMLUtil.NodePrinter(boolean prettyPrint)
Creates a new NodePrinter.

Parameters:
prettyPrint - if true string representation of an XML document will contain new-lines, with each sub-node indented
Method Detail

visit

public boolean visit(org.w3c.dom.Node node)
Adds the string representation appropriate at the beginning of the given Node. For example, for an element node, this would add the start tag with its attributes; for a document node, this would add the DOCTYPE declaration, and so on.

Specified by:
visit in interface XMLUtil.Visitor
Parameters:
node - the Node for which to generate a string representation
Returns:
false, so as never to stop the traversal

afterVisit

public void afterVisit(org.w3c.dom.Node node)
For an element node, adds the end tag for the given Node to the string representation of the XML document, if necessary.

Specified by:
afterVisit in interface XMLUtil.Visitor
Parameters:
node - the Node being visited

toString

public java.lang.String toString()
Returns a string representation of the Node that has been traversed using this NodePrinter, or the empty string if the Node has not yet been traversed.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the Node that has been traversed


Copyright © 2008 Edge Software, Co., Ltd.. All Rights Reserved.