Enhydra 3.0.3 API

org.enhydra.xml.xmlc
Class XMLCUtil

java.lang.Object
  |
  +--org.enhydra.xml.xmlc.XMLCUtil

public abstract class XMLCUtil
extends java.lang.Object

Utility methods for dealing with DOMs.


Field Summary
static int PRINT_ALL
          All Print options.
static int PRINT_CDATA
          Option to printNode to print the contents of Text nodes.
static int PRINT_COMMENT
          Option to printNode to print the contents of Comment nodes.
static int PRINT_DEFAULT
          Default print options.
static int PRINT_DOCUMENTTYPE
          Option to printNode to print the contents of DocumentType nodes.
static int PRINT_TEXT
          Option to printNode to print the contents of Text nodes.
 
Constructor Summary
XMLCUtil()
           
 
Method Summary
static Node copyNode(Node srcNode, Document destDocument)
          Deprecated. use Document.importNode
static java.lang.String dumpAttrs(Node node, boolean all)
          Generate string of attribute names and values, sorted by name.
static Text findFirstText(Node node)
          Find the first text descendent node of an element.
static Attr getAttributeByName(Node node, java.lang.String name)
          Find an attribute of a node by name.
static Element getElementById(java.lang.String id, Node node)
          Recursively search for an element by id starting at a node.
static Text getFirstText(Node node)
          Find the first text descendent node of an element.
static Element getRequiredElementById(java.lang.String id, Node node)
          Recursively search for an required element by id starting at a node.
static void printNode(java.lang.String msg, Node node, int options, java.io.PrintWriter out)
          Print a node and its children.
static void printNode(java.lang.String msg, Node node, java.io.OutputStream out)
          Print a node an its children.
static void printNode(java.lang.String msg, Node node, java.io.PrintWriter out)
          Print a node an its children.
static Node replaceNode(Node srcNode, Node destNode)
          Replace a node with a given one from another document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRINT_COMMENT

public static final int PRINT_COMMENT
Option to printNode to print the contents of Comment nodes.

PRINT_TEXT

public static final int PRINT_TEXT
Option to printNode to print the contents of Text nodes.

PRINT_CDATA

public static final int PRINT_CDATA
Option to printNode to print the contents of Text nodes.

PRINT_DOCUMENTTYPE

public static final int PRINT_DOCUMENTTYPE
Option to printNode to print the contents of DocumentType nodes.

PRINT_ALL

public static final int PRINT_ALL
All Print options.

PRINT_DEFAULT

public static final int PRINT_DEFAULT
Default print options.
Constructor Detail

XMLCUtil

public XMLCUtil()
Method Detail

getAttributeByName

public static Attr getAttributeByName(Node node,
                                      java.lang.String name)
Find an attribute of a node by name.
Parameters:
node - Node who's attribute is desired.
name - The name of the desired attribute.
Returns:
The attribute or null if its not found.

findFirstText

public static Text findFirstText(Node node)
Find the first text descendent node of an element. This recursively looks more than one level to search for text in font nodes, etc. If a text node is not found, return null
Parameters:
node - The starting node for the search.
Returns:
The text node or null if not found.

getFirstText

public static Text getFirstText(Node node)
Find the first text descendent node of an element. This recursively looks more than one level to search for text in font nodes, etc. If a text node is not found, generate an error.
Parameters:
node - The starting node for the search.
Returns:
The text node.
Throws:
XMLCError - If a text node was not found.

getElementById

public static Element getElementById(java.lang.String id,
                                     Node node)
Recursively search for an element by id starting at a node. Assumes id attribute is named "id". With XMLC, it normally better to access elements in a compiled objects directly with the generated access methods. This is provided for working on cloned pieces of the document or other tasks outside of the XMLC generated object.
Parameters:
id - The element id to find. Case is ignored.
node - The node to start the search at.
Returns:
A point the element if found, otherwise null.

getRequiredElementById

public static Element getRequiredElementById(java.lang.String id,
                                             Node node)
Recursively search for an required element by id starting at a node.
Parameters:
id - The element id to find. Case is ignored.
node - The node to start the search at.
Returns:
A point the element if found.
Throws:
XMLCError - Thrown if the element is not found.
See Also:
getElementById(java.lang.String, org.w3c.dom.Node)

dumpAttrs

public static java.lang.String dumpAttrs(Node node,
                                         boolean all)
Generate string of attribute names and values, sorted by name.
Parameters:
node - Get the attributes of this node.
all - If true, get all attributes, otherwise get only specified ones.
Returns:
A printable string.

printNode

public static void printNode(java.lang.String msg,
                             Node node,
                             int options,
                             java.io.PrintWriter out)
Print a node and its children.
Parameters:
msg - A message to print at the start. If null or empty, don't print a message.
node - Top of the tree.
options - Set of print options.
out - Output writer.

printNode

public static void printNode(java.lang.String msg,
                             Node node,
                             java.io.PrintWriter out)
Print a node an its children.
Parameters:
msg - A message to print at the start. If null or empty, don't print a message.
node - Top of the tree.
out - Output writer.

printNode

public static void printNode(java.lang.String msg,
                             Node node,
                             java.io.OutputStream out)
Print a node an its children.
Parameters:
msg - A message to print at the start. If null or empty, don't print a message.
node - Top of the tree.
out - Output stream.

copyNode

public static Node copyNode(Node srcNode,
                            Document destDocument)
Deprecated. use Document.importNode

Copy a node and its children from one document to another.
Parameters:
srcNode - The node to copy.
destDocument - The destination document. The node will belong to this document but will not be inserted in it.
Returns:
The new node.
See Also:
Document.importNode(org.w3c.dom.Node, boolean)

replaceNode

public static Node replaceNode(Node srcNode,
                               Node destNode)
Replace a node with a given one from another document.
Parameters:
srcElement - The node to clone and insert
destElement - The node to be replaced
Returns:
the new node that replaces the destination node

Enhydra 3.0.3 API