List of usage examples for org.w3c.dom Node getNodeValue
public String getNodeValue() throws DOMException;
From source file:Main.java
/** * Get the value of the attribute with the given name of the first tag found with the given tag name in the given * document<br/>./* w ww. ja v a 2 s .co m*/ * * @param doc * @param tagName * @param attributeName * @return the value of the attribute with the given name of the node or the empty string, if no node with this name * exits in this document or the attribute does not exist */ public static String getTagAttributeValue(Document doc, String tagName, String attributeName) { NodeList tagList = doc.getElementsByTagName(tagName); if (tagList.getLength() > 0) { NamedNodeMap attributes = tagList.item(0).getAttributes(); if (attributes != null) { Node attribute = attributes.getNamedItem(attributeName); if (attribute != null) { return attribute.getNodeValue().trim(); } } } return ""; }
From source file:Main.java
public static boolean nodeMatchesAttributeFilter(Node node, String str, List<String> list) { if (str == null || list == null) { return true; }/*from w ww . j a va 2s .c o m*/ NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { Node namedItem = attributes.getNamedItem(str); if (namedItem != null && list.contains(namedItem.getNodeValue())) { return true; } } return false; }
From source file:Main.java
public static String getTextContent(Element element) { StringBuilder buffer = new StringBuilder(); element.normalize();/*from www . j a va2s . c o m*/ NodeList children = element.getChildNodes(); for (int i = 0, n = children.getLength(); i < n; i++) { Node child = children.item(i); if (child.getNodeType() == Node.TEXT_NODE) { buffer.append(child.getNodeValue()); } } return buffer.toString().trim(); }
From source file:Main.java
/** * Helper class to help parse the server response. * /*from ww w.j a v a 2s. c o m*/ * @param nodeList * @return */ public static String getNodeTrimValue(NodeList nodeList) { Element element = (Element) nodeList.item(0); String nodeValue = ""; if (element != null) { NodeList itemNodeList = element.getChildNodes(); int length = itemNodeList.getLength(); for (int i = 0; i < length; i++) { Node node = ((Node) itemNodeList.item(i)); if (node != null) nodeValue += node.getNodeValue(); } if (nodeValue != null && !nodeValue.equals("")) { return nodeValue.trim(); } else { return null; } } return null; }
From source file:Main.java
/** * Gets an attribute value by name, returning null if not found *//*from w w w . j a va2 s. co m*/ public static String getAttributeByName(Node content, String attributeName) { if (content != null) { NamedNodeMap atts = content.getAttributes(); if (atts == null) { return null; } Node att = atts.getNamedItem(attributeName); if (att != null) { return att.getNodeValue(); } } return null; }
From source file:Main.java
/** * Get XML <code>Node</code> text content. This method duplicates the * org.w3c.dom.Node.getTextContent() method in JDK 1.5. * * @param baseNode The XML node from which the content is being retrieved. * @return The text content of the XML node. *///from w w w . ja v a 2s . c om public static String getTextContent(Node baseNode) { // if element, first child will be a text element with content Node child = baseNode.getFirstChild(); if (child != null && child.getNodeType() == Node.TEXT_NODE) { return child.getNodeValue(); } return ""; }
From source file:Main.java
public static String retrieveNodeAsString(Node node) { String nodeStr = new String("<"); nodeStr += node.getNodeName() + internal; if (node.hasAttributes()) { NamedNodeMap attrs = node.getAttributes(); // add the attrubite name-value pairs for (int i = 0; i < attrs.getLength(); i++) { Node a = attrs.item(i); nodeStr += a.getNodeName() + "=" + a.getNodeValue() + internal; }/*from w w w. ja v a2s .c o m*/ } if (node.hasChildNodes()) { nodeStr += ">\n"; NodeList ns = node.getChildNodes(); for (int i = 0; i < ns.getLength(); i++) { nodeStr += logXMLSubNode(ns.item(i), 1); } nodeStr += "<" + node.getNodeName() + "/>\n"; } else { nodeStr += "/>\n"; } return nodeStr; }
From source file:Main.java
/** * Insert the method's description here. * // w w w . j a v a 2 s. co m * @return java.lang.String * @param element * org.w3c.dom.Node * @param attributeName * java.lang.String */ public static String getNodeAttributeValue(Node element, String attributeName) { Node tmpNode = element.getAttributes().getNamedItem(attributeName); String tmp = null; if (tmpNode != null) tmp = tmpNode.getNodeValue(); return tmp; }
From source file:Main.java
public static void updateUserMgtXML(File userMgtXML, String jndiConfigNameUserDB) throws Exception { Document doc = initializeXML(userMgtXML); NodeList configNodeList = doc.getElementsByTagName("Configuration"); Node configNode = configNodeList.item(0); //get the 0 index, since only one available NodeList nodeList = configNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getNodeName().equalsIgnoreCase("Property")) { if (node.hasAttributes()) { NamedNodeMap namedNodeMap = node.getAttributes(); Node attr = namedNodeMap.getNamedItem("name"); if (attr != null && attr.getNodeValue().equalsIgnoreCase("dataSource")) { node.setTextContent(jndiConfigNameUserDB); }/*from w ww . ja v a 2 s . c om*/ } } } } finalizeXML(userMgtXML, doc, 4); }
From source file:org.springsource.ide.eclipse.commons.content.core.util.ContentUtil.java
public static String getAttributeValue(Node node, String attribute) { Node item = node.getAttributes().getNamedItem(attribute); return (item != null) ? item.getNodeValue() : null; }