List of usage examples for org.w3c.dom Node getNodeValue
public String getNodeValue() throws DOMException;
From source file:Main.java
static public String getNodeAttr(String attrName, Node node) { NamedNodeMap attrs = node.getAttributes(); for (int y = 0; y < attrs.getLength(); y++) { Node attr = attrs.item(y); if (attr.getNodeName().equalsIgnoreCase(attrName)) { return attr.getNodeValue(); }/* w w w. j a v a 2s. c o m*/ } return ""; }
From source file:Main.java
/** * Returns the double value of the named attribute for the given node * If no such attribute exists, returns 0.0 *//* ww w .ja va 2 s. com*/ public static double getDblValue(Node node, String name) { // Look for the attribute Node att = get_named_attribute(node, name); if (att != null) { // Return the value return Double.valueOf(att.getNodeValue()).doubleValue(); } else { // No such attribute return 0.0; } }
From source file:Main.java
/** * Returns the integer value of the named attribute for the given node * If no such attribute exists, returns 0 *///from w w w . j a v a 2 s.c om public static int getIntValue(Node node, String name) { // Look for the attribute Node att = get_named_attribute(node, name); if (att != null) { // Return the value return Integer.valueOf(att.getNodeValue()).intValue(); } else { // No such attribute return 0; } }
From source file:Main.java
/** * Returns the boolean value of the named attribute for the given node * If no such attribute exists, returns false *///ww w.j av a 2 s . co m public static boolean getBoolValue(Node node, String name) { // Look for the attribute Node att = get_named_attribute(node, name); if (att != null) { // Return the value return Boolean.valueOf(att.getNodeValue()).booleanValue(); } else { // No such attribute return false; } }
From source file:Main.java
/** * Get the attribute with given name's value * /*from w w w . j a va 2s . co m*/ * @param node * the node which attribute's value is returned * @param name * name of the attribute * @return the value af the attribute */ public static String getAttributeByName(Node node, String name) { if (node == null) { return null; } Node attribute = node.getAttributes().getNamedItem(name); if (attribute == null) { return null; } else { return attribute.getNodeValue().trim(); } }
From source file:Main.java
/** * Gets the text value contained in an element. * * @param node The Element to get the text value of. * * @return The text in the element./* w w w.ja v a2 s .com*/ */ public static String getTextValue(Element node) { if (node == null) { return null; } NodeList nodes = node.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); if (n.getNodeType() == n.TEXT_NODE) { return n.getNodeValue(); } } return null; }
From source file:Main.java
public static String getText(final Node node) { final StringBuilder result = new StringBuilder(); if (!node.hasChildNodes()) return ""; final NodeList list = node.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node subnode = list.item(i); if (subnode.getNodeType() == Node.TEXT_NODE) { result.append(subnode.getNodeValue()); } else if (subnode.getNodeType() == Node.CDATA_SECTION_NODE) { result.append(subnode.getNodeValue()); } else if (subnode.getNodeType() == Node.ENTITY_REFERENCE_NODE) { // Recurse into the subtree for text // (and ignore comments) result.append(getText(subnode)); }/* ww w . j ava 2 s. c om*/ } return result.toString(); }
From source file:Main.java
/** * Returns the value of given tagName under given element. * //from ww w. j av a2s .c om * E.g. * <ele> * <tagName>MyValue</tagName> * </ele> * * MyValue is returned in the above case. * * @param ele xml element under which the tagName should be found * @param tagName tag name of the tag which value is read * @return the value of given tagName under given element. */ public static String getTextValue(Element ele, String tagName) { String textVal = null; try { NodeList nl = ele.getElementsByTagName(tagName); if (nl != null && nl.getLength() > 0) { Element el = (Element) nl.item(0); Node firstChild = el.getFirstChild(); if (firstChild != null) textVal = firstChild.getNodeValue(); } } catch (Exception e) { e.printStackTrace(); } return textVal; }
From source file:XMLUtils.java
/** * Returns a list of value for the given node. * @param ns the namespace./*w w w . j av a 2s . co m*/ * @param base the element from where to search. * @param name of the element to get. * @return the list of value of this element. */ public static List<String> getStringListValueElement(final String ns, final Element base, final String name) { List<String> returnedlist = new ArrayList<String>(); // Get element NodeList list = base.getElementsByTagNameNS(ns, name); int length = list.getLength(); // Get all values of all elements if (length > 0) { for (int i = 0; i < length; i++) { Element element = (Element) list.item(i); Node node = element.getFirstChild(); if (node != null) { returnedlist.add(node.getNodeValue()); } } } return returnedlist; }
From source file:Main.java
/** * Compares the attributes of two XML <code>Node</code> objects. This method * returns <code>true</code> if all attribute name-value pairs match * disregarding their order of placement. * //w ww . ja v a 2s. com * @param n1 first <code>Node</code> * @param n2 second <code>Node</code> * * @return boolean * */ public static boolean diffAttributes(Node n1, Node n2) { NamedNodeMap n1Atts = n1.getAttributes(); NamedNodeMap n2Atts = n2.getAttributes(); if (n1Atts.getLength() != n2Atts.getLength()) { return false; } for (int i = 0; i < n1Atts.getLength(); i++) { Node a1 = n1Atts.item(i); Node a2Val = n2Atts.getNamedItem(a1.getNodeName()); if (a2Val == null || !a1.getNodeValue().equals(a2Val.getNodeValue())) { return false; } } return true; }