List of usage examples for org.w3c.dom Node getNodeValue
public String getNodeValue() throws DOMException;
From source file:Main.java
private static String getStringValue(String attrName, Map<String, String> runtimeAttributes, Node docElement) { String stringValue = runtimeAttributes.get(attrName); if (stringValue == null) { Node staleNode = docElement.getAttributes().getNamedItem(attrName); if (staleNode != null) { stringValue = staleNode.getNodeValue(); }//from www .j a v a 2 s .c om } return stringValue; }
From source file:Main.java
public static String getTextContent(Node node) { StringBuffer buffer = new StringBuffer(); NodeList childList = node.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { Node child = childList.item(i); if (child.getNodeType() != Node.TEXT_NODE) continue; // skip non-text nodes buffer.append(child.getNodeValue()); }/*from w ww. j ava2s.com*/ return buffer.toString(); }
From source file:Main.java
/** * /*ww w . java2 s .co m*/ * @param currentNode * @param tagName * @param attributeValue * @return */ public static String getTextContentByElementNameANDAttributeValue(Node currentNode, String tagName, String attributeValue) { String result = ""; NodeList childNodeList = currentNode.getChildNodes(); for (int i = 0; i < childNodeList.getLength(); i++) { Node childNode = childNodeList.item(i); switch (childNode.getNodeType()) { case Node.DOCUMENT_NODE: break; case Node.ELEMENT_NODE: Element childElement = (Element) childNodeList.item(i); // logger.debug("childElement name : " + childElement.getTagName()); if (childElement != null && childElement.getNodeName().equals(tagName)) { NamedNodeMap attributes = childElement.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { Node current = attributes.item(j); if (current.getNodeName().equals("type") && current.getNodeValue().equals(attributeValue)) { result = childElement.getTextContent(); break; } } } case Node.TEXT_NODE: // logger.debug("textElement name : " + currentNode.getNodeValue()); break; case Node.COMMENT_NODE: break; case Node.PROCESSING_INSTRUCTION_NODE: break; case Node.ENTITY_REFERENCE_NODE: break; case Node.DOCUMENT_TYPE_NODE: break; } } return result; }
From source file:Main.java
/** * Extracts the inner text value from a xml node accept : <node>value</node> and return value * string//from w ww . j a v a 2 s .c o m * * @param node XML node to extract inner text from * @return innerText if its not empty otherwise null. */ private static String getNodeTextValue(Node node) { String innerText = null; if (node != null) { Node textNode = node.getFirstChild(); if (textNode != null && textNode.getNodeType() == Node.TEXT_NODE) { innerText = textNode.getNodeValue(); innerText = innerText.trim(); if (innerText.length() == 0) { innerText = null; } } } return innerText; }
From source file:Main.java
public static String getTextContent(Node node, boolean trim) { if (node == null) { return ""; }//from w w w . j a v a 2 s .c om String textContent = ""; NodeList childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node childNode = childNodes.item(i); if (childNode.getNodeType() == Node.TEXT_NODE) { textContent += childNode.getNodeValue().trim(); } } textContent = textContent.replace("\r", ""); if (textContent.startsWith("\n")) { textContent = textContent.substring(1); } if (trim) { textContent = textContent.trim(); } return textContent; }
From source file:Main.java
public static final String getText(Node node) { if (node.hasChildNodes()) { NodeList childNodes = node.getChildNodes(); if (childNodes.getLength() > 0) { Node child = childNodes.item(0); if ((child.getNodeType() == Node.CDATA_SECTION_NODE) || (child.getNodeType() == Node.TEXT_NODE)) { return child.getNodeValue(); }//from ww w .j a v a2 s . c o m } } return null; }
From source file:Main.java
/** * Gets attribute value of a node./*from www . java2s. c om*/ * * @param node * a node * @param namespaceURI * attribute namespace URI * @param attrName * attribute name * @return attribute value */ public static String getNodeAttributeValueNS(Node node, String namespaceURI, String attrName) { NamedNodeMap attrs = node.getAttributes(); if (attrs == null) { return null; } Node value = attrs.getNamedItemNS(namespaceURI, attrName); if (value == null) { return null; } return value.getNodeValue(); }
From source file:Main.java
/** * Gets the node value as long.// w w w . ja va2 s. com * *@param node Description of the Parameter *@return The nodeValueAsLong value *@exception DOMException Description of the Exception */ public final static long getNodeValueAsLong(Node node) throws DOMException { if (node != null) { node = node.getFirstChild(); if (node != null) return Long.parseLong(node.getNodeValue()); } return -1; }
From source file:Main.java
public static StringBuilder append(Node n, StringBuilder buf, int level) { if (n instanceof CharacterData) return _level(buf, level).append(n.getNodeValue()).append("\n"); _level(buf, level).append("<").append(n.getNodeName()); NamedNodeMap attr = n.getAttributes(); if (attr != null) { for (int i = 0; i < attr.getLength(); i++) { Node a = attr.item(i); buf.append(" ").append(a.getNodeName()).append("=\"").append(a.getNodeValue()).append("\" "); }//from w w w . j a va 2 s. co m } NodeList children = n.getChildNodes(); if (children == null || children.getLength() == 0) return buf.append("/>\n"); buf.append(">\n"); for (int i = 0; i < children.getLength(); i++) { Node c = children.item(i); append(c, buf, level + 1); } return _level(buf, level).append("</").append(n.getNodeName()).append(">\n"); }
From source file:Main.java
/** * Extract the text symbol from the given DOM element, ignoring XML comments. * <p>Appends all CharacterData nodes and EntityReference nodes * into a single String symbol, excluding Comment nodes. * @see CharacterData// ww w . j ava2 s . c o m * @see EntityReference * @see Comment */ public static String getTextValue(Element valueEle) { StringBuffer value = new StringBuffer(); NodeList nl = valueEle.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node item = nl.item(i); if (item instanceof CharacterData && !(item instanceof Comment) || item instanceof EntityReference) value.append(item.getNodeValue()); } return value.toString(); }