List of usage examples for org.w3c.dom Node getNodeValue
public String getNodeValue() throws DOMException;
From source file:Main.java
public static String getElementValue(Element p_element) { Node n = p_element.getFirstChild(); if (n != null) { return n.getNodeValue(); }//from www .j a v a2 s.c o m return null; }
From source file:Main.java
/** * Converts XML {@code <property name=""></property>} tags to Properties * object./*w w w .j a v a2 s .c o m*/ * * @see java.util.XmlUtils.importProperties() * * @param entries * List of property nodes in the DOM */ public static Properties importProperties(NodeList entries) { Properties props = new Properties(); int numEntries = entries.getLength(); for (int i = 0; i < numEntries; i++) { Element entry = (Element) entries.item(i); if (entry.hasAttribute("name")) { Node n = entry.getFirstChild(); String val = (n == null) ? "" : n.getNodeValue(); props.setProperty(entry.getAttribute("name"), val); } } return props; }
From source file:TestDOM.java
public static String getSimpleElementText(Element node) { StringBuffer sb = new StringBuffer(); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Text) sb.append(child.getNodeValue()); }/*from ww w .ja va 2s. c o m*/ return sb.toString(); }
From source file:Main.java
public static String getSimpleElementText(Element node) { if (node == null) return null; StringBuffer sb = new StringBuffer(); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Text) { sb.append(child.getNodeValue()); }/*from www . ja v a 2 s. co m*/ } return sb.toString(); }
From source file:Main.java
public static String getText(Node node) { String text = ""; NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeType() == Node.TEXT_NODE) { text += child.getNodeValue() + " "; }/*from w w w . j a v a2 s . c o m*/ } return text; }
From source file:Main.java
public static void printNodeList(NodeList nodeList) { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); buffer.append(node.getNodeName() + " = " + node.getNodeValue() + " Attributes: " + attributesStr(node) + "\n"); }// w ww . jav a 2 s . c o m logger.info(buffer); }
From source file:Main.java
/** * @param element/* w ww.j a va2 s . c o m*/ * @param map * @return */ private static boolean fillAttsIntoMap(Element element, Map<String, String> map) { /* * this case is applicable only if there are no child elements */ if (element.getChildNodes().getLength() > 0) { return false; } /* * in case this is not a special case, it will not have attributes, and * hence we are safe */ NamedNodeMap attrs = element.getAttributes(); int n = attrs.getLength(); for (int i = 0; i < n; i++) { Node att = attrs.item(i); map.put(att.getNodeName(), att.getNodeValue()); } return true; }
From source file:Main.java
public static String getNamespaceURI(Document doc, String ns) { NamedNodeMap attr = doc.getDocumentElement().getAttributes(); for (int i = 0; i < attr.getLength(); i++) { Node attrNode = attr.item(i); if (attrNode.getNodeName().indexOf(ns) != -1) { return (attrNode.getNodeValue()); }//from w w w .j a va 2s .c om } return null; }
From source file:Main.java
public static String getNodeAttribute(Node n, String attrName) { Node namedAttr = n.getAttributes().getNamedItem(attrName); if (namedAttr != null) return namedAttr.getNodeValue(); else/*from www . j av a 2s. c o m*/ return null; }
From source file:Main.java
public static void incrementAttributeValue(Node node, String attName, int value) { Node attr = node.getAttributes().getNamedItem(attName); String attValue = String.valueOf(Integer.parseInt(attr.getNodeValue()) + value); attr.setNodeValue(attValue);/*from w w w . ja v a 2 s .co m*/ }