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 intfindAttributeValue(NodeList nodeList, String attrName, String attrValue)SearchesnodeListfor the first elementelemmatchingelem.getAttribute(attrName).equals(attrValue).static String[]formatAttributes(Node nd)Formats all attributes ofnd.static String[]formatChildNodes(Node nd)Formats all child nodes ofnd.protected static StringformatType(short nodeType)Replaces the numerical node type by a descriptive Letter.static StringgetAttributeValue(Node nd, String attrName)Other thanElement.getAttribute(java.lang.String)this method can be called onndof any node type and returns the empty string, ifndis not anElement.static Element[]getChildElements(Node nd)Other thanNode.getChildNodes()this method only returns nodes of typeElement.static StringtoString(Node nd)Formatsnd. Used to analyse a DOM.
-
-
-
Method Detail
-
findAttributeValue
public static int findAttributeValue(NodeList nodeList, String attrName, String attrValue)
SearchesnodeListfor the first elementelemmatchingelem.getAttribute(attrName).equals(attrValue).- Parameters:
nodeList- e.g. result fromNode.getChildNodes()attrName- the name of the attribute checked forattrValueattrValue- 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 onndof any node type and returns the empty string, ifndis not anElement.- Parameters:
nd- can be of any node typeattrName- the name of the attribute to retrieve- Returns:
((Element)nd).getAttribute(attrName)ifndis anElementor 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
ndwhich areinstanceofElement.
-
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
- See Also:
Node.getNodeType(),formatType(short),Node.getAttributes(),Node.getChildNodes(),Node.getNodeName(),Node.getNodeValue(),Node.getTextContent()
-
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
ndformatted as string or an empty array ifndhas no attributes - See Also:
Node.getAttributes()
-
formatChildNodes
public static String[] formatChildNodes(Node nd)
Formats all child nodes ofnd.- Parameters:
nd- can be of any node type- Returns:
- array of the child nodes of
ndformatted as string or an empty array ifndhas no child nodes - See Also:
Node.getChildNodes()
-
formatType
protected static String formatType(short nodeType)
Replaces the numerical node type by a descriptive Letter.
E Element R EntityReference D Document A Attribute I Entity T DocumentType X Text P ProcessingInstruction F DocumentFragment S CDATASection C Comment N Notation - See Also:
- Constant Field Values,
Node.ELEMENT_NODE
-
-