|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.javaranch.common.DOM
Some static method shortcuts to help with working with DOM.
- - - - - - - - - - - - - - - - -
Copyright (c) 1999-2004 Paul Wheaton
You are welcome to do whatever you want to with this source file provided that you maintain this comment fragment (between the dashed lines). Modify it, change the package name, change the class name ... personal or business use ... sell it, share it ... add a copyright for the portions you add ...
My goal in giving this away and maintaining the copyright is to hopefully direct developers back to JavaRanch.
The original source can be found at JavaRanch
- - - - - - - - - - - - - - - - -
Constructor Summary | |
DOM()
|
Method Summary | |
static java.lang.String |
getAllText(org.w3c.dom.Element node)
Given an element, find all of the text children and concatenate them together. |
static boolean |
getBooleanAttribute(org.w3c.dom.Element node,
java.lang.String attributeName,
java.lang.String trueText,
boolean defaultValue)
Get the boolean representation of the attribute. |
static org.w3c.dom.NodeList |
getChildren(org.w3c.dom.Node node,
java.lang.String tagName)
Retreives all of the children that have this particular tag name. |
static java.lang.String |
getChildText(org.w3c.dom.Element node,
java.lang.String childName)
Find the child element and extract it's text with getText(). |
static int |
getIntAttribute(org.w3c.dom.Element node,
java.lang.String attributeName)
Get the int representation of the attribute. |
static org.w3c.dom.Element |
getRoot(java.lang.String xml)
Pass in an XML string and get back the root DOM element. |
static java.lang.String |
getText(org.w3c.dom.Element node)
given an element, extract the text. |
static java.lang.String |
getTextAttribute(org.w3c.dom.Element node,
java.lang.String attributeName)
Get the String representation of the attribute. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public DOM()
Method Detail |
public static java.lang.String getTextAttribute(org.w3c.dom.Element node, java.lang.String attributeName)
public static int getIntAttribute(org.w3c.dom.Element node, java.lang.String attributeName) throws java.lang.Exception
Throws an exception if there is no match.
java.lang.Exception
public static boolean getBooleanAttribute(org.w3c.dom.Element node, java.lang.String attributeName, java.lang.String trueText, boolean defaultValue)
trueText
- If the text in DOM matches this string, true will be returned. defaultValue
- If the attribute is not found, this is what will be returned. public static java.lang.String getText(org.w3c.dom.Element node)
Useful only if you know there is nothing between the node tags other than text. If there are other tags, this will return whatever text appears before the first tag.
public static java.lang.String getAllText(org.w3c.dom.Element node)
All leading and trailing whitespace will be removed.
public static java.lang.String getChildText(org.w3c.dom.Element node, java.lang.String childName) throws java.lang.Exception
java.lang.Exception
public static org.w3c.dom.NodeList getChildren(org.w3c.dom.Node node, java.lang.String tagName)
public static org.w3c.dom.Element getRoot(java.lang.String xml) throws java.lang.Exception
java.lang.Exception
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |