ch.claudio.lib
Class DOMUtil

java.lang.Object
  extended by ch.claudio.lib.DOMUtil

public class DOMUtil
extends java.lang.Object

Version:
$Id: DOMUtil.java 177 2007-04-05 23:22:21Z claudio $
Author:
Claudio Nieder

Field Summary
static java.lang.String[] nodeTypeNames
          Array mapping note type to a readable name
 
Method Summary
static void dumpLevelAndBelow(java.io.PrintWriter out, org.w3c.dom.Node main, java.lang.String prefix)
          Dump all siblings of the starting node together with all children.
static java.util.List<org.w3c.dom.Node> findAll(org.w3c.dom.Node start, java.lang.String name)
          Find all siblings and decendants of the starting node which have the requested node name.
static java.lang.String getAttributeOf(org.w3c.dom.Node start, java.lang.String tag, java.lang.String attributeName)
          Get an attribute from first sibling or child node of the starting node
static org.w3c.dom.Node getSiblingByName(org.w3c.dom.Node start, java.lang.String name)
          Find first sibling of the starting node whose name matches the requested one.
static boolean hasAttributeValue(org.w3c.dom.Node node, java.lang.String name, java.lang.String value)
          Test if a node has an attribute with given value.
static void main(java.lang.String[] args)
          Dump URLs passed by argument
static org.w3c.dom.Document parse(java.net.URL url)
          Fetch a file and parse it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nodeTypeNames

public static final java.lang.String[] nodeTypeNames
Array mapping note type to a readable name

Method Detail

getSiblingByName

public static org.w3c.dom.Node getSiblingByName(org.w3c.dom.Node start,
                                                java.lang.String name)
Find first sibling of the starting node whose name matches the requested one. This can be the starting node itself.

Parameters:
start - starting node
name - name of searched tag
Returns:
node or null

findAll

public static java.util.List<org.w3c.dom.Node> findAll(org.w3c.dom.Node start,
                                                       java.lang.String name)
Find all siblings and decendants of the starting node which have the requested node name. This can include the starting node itself.

Parameters:
start - starting node
name - node name to look for
Returns:
list. never null but maybe empty

getAttributeOf

public static java.lang.String getAttributeOf(org.w3c.dom.Node start,
                                              java.lang.String tag,
                                              java.lang.String attributeName)
Get an attribute from first sibling or child node of the starting node

Parameters:
start -
tag -
attributeName -
Returns:
attribute value

hasAttributeValue

public static boolean hasAttributeValue(org.w3c.dom.Node node,
                                        java.lang.String name,
                                        java.lang.String value)
Test if a node has an attribute with given value.

Parameters:
node -
name -
value -
Returns:
true if the attribute exists and has the right value

dumpLevelAndBelow

public static void dumpLevelAndBelow(java.io.PrintWriter out,
                                     org.w3c.dom.Node main,
                                     java.lang.String prefix)
Dump all siblings of the starting node together with all children.

Parameters:
out - Printwriter for the output
main - starting node
prefix - prefix string prepended to each line

parse

public static org.w3c.dom.Document parse(java.net.URL url)
Fetch a file and parse it.

Parameters:
url - URL
Returns:
document

main

public static void main(java.lang.String[] args)
Dump URLs passed by argument

Parameters:
args - URLs to fetch and dumpt