Class KmgXMLUtil
- java.lang.Object
-
- KmgXMLUtil
-
public class KmgXMLUtil extends Object
Collection of (static) methods adding to packageorg.w3c.dom
.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
findAttributeValue(NodeList nodeList, String attrName, String attrValue)
SearchesnodeList
for the first elementelem
matchingelem.getAttribute(attrName).equals(attrValue)
.static String[]
formatAttributes(Node nd)
Formats all attributes ofnd
.static String[]
formatChildNodes(Node nd)
Formats all child nodes ofnd
.static String
getAttributeValue(Node nd, String attrName)
Other thanElement.getAttribute(java.lang.String)
this method can be called onnd
of any node type and returns the empty string, ifnd
is not anElement
.static Element[]
getChildElements(Node nd)
Other thanNode.getChildNodes()
this method only returns nodes of typeElement
.static String
toString(Node nd)
Formatsnd
. Used to analyse a DOM.
-
-
-
Method Detail
-
findAttributeValue
public static int findAttributeValue(NodeList nodeList, String attrName, String attrValue)
SearchesnodeList
for the first elementelem
matchingelem.getAttribute(attrName).equals(attrValue)
.- Parameters:
nodeList
- e.g. result fromNode.getChildNodes()
attrName
- the name of the attribute checked forattrValue
attrValue
- for a match the attribute value equals this parameter- Returns:
- index of the first element matching or -1 if not found
int i = KmgXMLUtil.findAttributeValue( nodeList, attrName, attrValue ); ⇒ i == -1 || nodeList.item(i).getAttribute( attrName ).equals( attrValue )
- See Also:
Node.getChildNodes()
,Element.getAttribute(java.lang.String)
-
getAttributeValue
public static String getAttributeValue(Node nd, String attrName)
Other thanElement.getAttribute(java.lang.String)
this method can be called onnd
of any node type and returns the empty string, ifnd
is not anElement
.- Parameters:
nd
- can be of any node typeattrName
- the name of the attribute to retrieve- Returns:
((Element)nd).getAttribute(attrName)
ifnd
is anElement
or the empty string otherwise
-
getChildElements
public static Element[] getChildElements(Node nd)
Other thanNode.getChildNodes()
this method only returns nodes of typeElement
.- Parameters:
nd
- can be of any node type- Returns:
- all child nodes of
nd
which areinstanceof
Element
.
-
toString
public static String toString(Node nd)
Formatsnd
. Used to analyse a DOM.- Parameters:
nd
- can be of any node type- Returns:
- node type, number of attributes, number of child nodes, node name, node value and text content
-
formatAttributes
public static String[] formatAttributes(Node nd)
Formats all attributes ofnd
.- Parameters:
nd
- can be of any node type- Returns:
- array of the attributes of
nd
formatted as string or an empty array ifnd
has no attributes
-
-