List of usage examples for org.w3c.dom Node getNodeValue
public String getNodeValue() throws DOMException;
From source file:lineage2.gameserver.utils.XMLUtil.java
/** * Method getAttributeValue./*w ww . ja va 2 s . c o m*/ * @param n Node * @param item String * @return String */ public static String getAttributeValue(Node n, String item) { final Node d = n.getAttributes().getNamedItem(item); if (d == null) { return StringUtils.EMPTY; } final String val = d.getNodeValue(); if (val == null) { return StringUtils.EMPTY; } return val; }
From source file:Main.java
/** * @param n Node to examine/*from w w w . j a v a2s.c o m*/ * @param attr Attribute to look for * @param def Default value to return if attribute is not present * @return if the Node contains the named Attribute, the value, if not, the * def parameter */ public static String getAttribute(Node n, String attr, String def) { NamedNodeMap attrs = n.getAttributes(); if (attrs == null) { return def; } Node ret = attrs.getNamedItem(attr); if (ret == null) { return def; } else { return ret.getNodeValue(); } }
From source file:Main.java
public static String getContent(Node n) { assertNotNull("node == null", n); StringBuilder result = new StringBuilder(); if (n.getNodeType() == Node.TEXT_NODE) { result.append(n.getNodeValue()); }/*from w w w . j ava 2 s . c om*/ NodeList childNodes = n.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node n2 = childNodes.item(i); result.append(getContent(n2)); } String tmp = result.toString(); return tmp.replaceAll(CHAR_NBSP, " "); }
From source file:Main.java
/** * Constructs a XPath query to the supplied node. * // w ww. ja va2 s . c om * @param n * @return */ public static String getXPath(Node n) { if (null == n) { throw new IllegalArgumentException("Invalid node"); } ArrayList<Node> hierarchy = new ArrayList<Node>(); StringBuffer buffer = new StringBuffer(); Node parent = null; // Push parent element's on stack hierarchy.add(n); parent = n.getParentNode(); while (parent != null && parent.getNodeType() != Node.DOCUMENT_NODE) { hierarchy.add(0, parent); parent = parent.getParentNode(); } Iterator<Node> i = hierarchy.iterator(); while (i.hasNext()) { Node node = i.next(); buffer.append("/"); buffer.append(node.getNodeName()); if (node.hasAttributes()) { Node uuid = node.getAttributes().getNamedItem("uuid"); if (uuid != null) { buffer.append("[@uuid='"); buffer.append(uuid.getNodeValue()); buffer.append("']"); } } } // return buffer return buffer.toString(); }
From source file:Main.java
public static String[] getAttributes(final Node node, final String[] attributeNames) { final String[] valueList = new String[attributeNames.length]; final NamedNodeMap attMap = node.getAttributes(); Node tmpNode = null; for (int i = 0; i < attributeNames.length; i++) { try {//from ww w . j a v a 2 s . c o m tmpNode = attMap.getNamedItem(attributeNames[i]); valueList[i] = tmpNode.getNodeValue(); } catch (Exception e) { valueList[i] = ""; } } // next attribute return valueList; }
From source file:com.autentia.tnt.xml.UtilitiesXML.java
/** * Devuelve el valor del atributo "nombre" de un nodo * @param nombre//www. j av a 2 s. c om * @param nodo * @return */ public static String giveAttributeNode(String name, Node node) { NamedNodeMap map = node.getAttributes(); String value = null; if (map != null) { Node nodoAt = map.getNamedItem(name); if (nodoAt != null) value = nodoAt.getNodeValue(); } return value; }
From source file:Main.java
/** * Gets a TEXT node value from the specified Element node. * * @param element a ELEMENT Node has TEXT node *//*w ww . jav a 2s. c o m*/ /* TODO: Child? */ public static String getTextData(Node element) { if (element.getNodeType() != Node.ELEMENT_NODE) { throw new IllegalArgumentException(element + " is not ELEMENT node"); } Node description = element.getNextSibling(); if (description.getNodeType() != Node.TEXT_NODE) { throw new IllegalArgumentException(description + " is not TEXT node"); } return description.getNodeValue(); }
From source file:Main.java
/** * This method yields the Attribute at the node extracted by the expression. * @param parentNode The node to start at. * @param expression The XPath expression to evaluate. * @param attribute The Name of the attribute you would like to extract from the * XPath'd node./*from w w w .j a v a 2 s .c o m*/ * @return The Value of the attribute, or the empty String if no matching node * or matching attribute could be found. * @throws XPathExpressionException * * @author <a href='mailto:intere@gmail.com'>Eric Internicola</a> */ public static String getAttribute(Node parentNode, String expression, String attribute) throws XPathExpressionException { String attr = ""; Node n = getNode(parentNode, expression); if (n != null) { n = n.getAttributes().getNamedItem(attribute); } if (n != null) { attr = n.getNodeValue(); } return attr; }
From source file:Main.java
private static boolean hasEqualAttributes(Node arg0, Node arg) { NamedNodeMap map1 = arg0.getAttributes(); NamedNodeMap map2 = arg.getAttributes(); int len = map1.getLength(); if (len != map2.getLength()) { return false; }/*w ww . j a v a 2 s .c o m*/ for (int i = 0; i < len; i++) { Node n1 = map1.item(i); if (n1.getNodeName() != null) { Node n2 = map2.getNamedItem(n1.getNodeName()); if (n2 == null) { return false; } else if (!n1.getNodeValue().equals(n2.getNodeValue())) { return false; } } } return true; }
From source file:Main.java
/** * return the text content of an element *//*ww w .j a va 2 s . c o m*/ public static String getTextContent(org.w3c.dom.Node element) { StringBuffer childtext = new StringBuffer(); NodeList childlist = element.getChildNodes(); int ct = childlist.getLength(); for (int j = 0; j < ct; j++) { org.w3c.dom.Node childNode = childlist.item(j); if ((childNode.getNodeType() == Node.TEXT_NODE) || (childNode.getNodeType() == Node.CDATA_SECTION_NODE)) { childtext.append(childNode.getNodeValue().trim()); } } return childtext.toString(); }