List of usage examples for org.w3c.dom Node getNodeValue
public String getNodeValue() throws DOMException;
From source file:Main.java
/** * Gets an attribute value or an empty string if not found * /*ww w . ja va 2 s . c o m*/ * @param node Node with the attribute * @param attrName Name of the attribute * @return Value of the attribute or empty string if not found */ public static String getAttribute(Node node, String attrName) { NamedNodeMap attributes = node.getAttributes(); if (attributes == null) return ""; Node attr = attributes.getNamedItem(attrName); if (attr != null) { return attr.getNodeValue(); } else { return ""; } }
From source file:Main.java
public static String getSubTagValue(Element root, String tagName, String subTagName) { String returnString = ""; NodeList list = root.getElementsByTagName(tagName); for (int loop = 0; loop < list.getLength(); loop++) { Node node = list.item(loop); if (node != null) { NodeList children = node.getChildNodes(); for (int innerLoop = 0; innerLoop < children.getLength(); innerLoop++) { Node child = children.item(innerLoop); if ((child != null) && (child.getNodeName() != null) && child.getNodeName().equals(subTagName)) { Node grandChild = child.getFirstChild(); if (grandChild.getNodeValue() != null) return grandChild.getNodeValue(); }//from ww w. j ava 2s . c o m } // end inner loop } } return returnString; }
From source file:Main.java
public static String getAttribute(Node node, String name) { NamedNodeMap attr = node.getAttributes(); for (int n = 0; n < attr.getLength(); n++) { Node attribute = attr.item(n); if (attribute.getNodeName().equals(name)) return attribute.getNodeValue(); }//from w w w . j a v a 2 s . c o m return ""; }
From source file:Main.java
public static String getNodeText(Node paramNode) { if (paramNode == null) return null; String str = paramNode.getNodeValue(); if ("null".equals(str)) return null; return str;/*from w w w . j av a 2 s.co m*/ }
From source file:Main.java
public static String getStringValueForXMLTag(Element xmlElement, String key) { NodeList nl = xmlElement.getElementsByTagName(key); if (nl.getLength() > 0) { Node node = nl.item(0).getFirstChild(); if (node != null) { String output = node.getNodeValue().trim(); return output; }//from w w w. j ava 2 s. c o m } return ""; }
From source file:Main.java
public static void printNodeList(ArrayList<Node> nodeList) { StringBuffer buffer = new StringBuffer(); for (Node node : nodeList) { buffer.append(node.getNodeName() + " = " + node.getNodeValue() + " Attributes: " + attributesStr(node) + "\n"); }/*from w w w .j a v a 2 s . com*/ logger.info(buffer); }
From source file:Main.java
/** * Returns string value of the named attribute of the node. * Returns <code>null</code> if such attribute does not exist. * * @param node The node to extract attribute from * @param attrName The name of the attribute * * @return String value of the attribute or <code>null</code> * * @throws NullPointerException If <code>node</code> is <code>null</code> *///from www . j ava2 s .co m public static String getAttributeValue(Node node, String attrName) { Node attr = node.getAttributes().getNamedItem(attrName); return attr == null ? null : attr.getNodeValue(); }
From source file:Main.java
public static String getSubTagValue(Element root, String tagName, String subTagName) { String returnString = ""; NodeList list = root.getElementsByTagName(tagName); for (int loop = 0; loop < list.getLength(); loop++) { Node node = list.item(loop); if (node != null) { NodeList children = node.getChildNodes(); for (int innerLoop = 0; innerLoop < children.getLength(); innerLoop++) { Node child = children.item(innerLoop); if ((child != null) && (child.getNodeName() != null) && (child.getNodeName().equals(subTagName))) { Node grandChild = child.getFirstChild(); if (grandChild.getNodeValue() != null) { return grandChild.getNodeValue(); }//www .j a v a2 s .com } } } } return returnString; }
From source file:Main.java
/** * * @param element Element/*from w ww . j a v a 2 s. co m*/ * @param namespace String * @param childName String * @return String */ public static String getChildStringNS(Element element, String namespace, String childName) { NodeList nodes = element.getElementsByTagNameNS(namespace, childName); if (nodes.getLength() > 0) { Node fnd = nodes.item(0).getFirstChild(); if (fnd != null) return fnd.getNodeValue(); } return ""; }
From source file:Main.java
public static String getAttribute(Node node, String attrName) { NamedNodeMap attr = node.getAttributes(); if (attr != null) { Node nodeAttr = attr.getNamedItem(attrName); if (nodeAttr != null) { return nodeAttr.getNodeValue(); }/*from w w w . java 2 s. c om*/ } return null; }