List of usage examples for org.w3c.dom Node getNodeValue
public String getNodeValue() throws DOMException;
From source file:Main.java
public static String getValue(Element el) { if (el != null) { NodeList nodes = el.getChildNodes(); StringBuffer sb = new StringBuffer(); // String s; int length = nodes.getLength(); for (int i = 0; i < length; ++i) { Node node = nodes.item(i); String s = null;/* www . j a v a2 s .co m*/ s = node.getNodeValue(); // System.out.println("XMLUtil.getValue: s=" + s); if (s != null) sb.append(s.trim()); } if (sb.length() > 0) { if (debug) { System.out.println("XMLUtil.getValue: sb=" + sb.toString()); } return sb.toString(); } } return null; }
From source file:Main.java
private static String logXMLSubNode(Node node, int deepth) { int i;/*from w ww . j a va 2 s. co m*/ String nodeStr = new String(); String interStr = new String(); for (i = 0; i < deepth; i++) interStr += "\t"; nodeStr += interStr + "<" + node.getNodeName() + internal; if (node.hasAttributes()) { NamedNodeMap attrs = node.getAttributes(); // add the attrubite name-value pairs for (i = 0; i < attrs.getLength(); i++) { Node a = attrs.item(i); nodeStr += a.getNodeName() + "=" + a.getNodeValue() + internal; } } if (node.hasChildNodes()) { nodeStr += ">\n"; NodeList ns = node.getChildNodes(); for (i = 0; i < ns.getLength(); i++) { nodeStr += logXMLSubNode(ns.item(i), deepth + 1); } nodeStr += interStr + "</" + node.getNodeName() + ">\n"; } else { if (node.getNodeValue() != null) { nodeStr += ">" + node.getNodeValue() + "<" + node.getNodeName(); } nodeStr += "/>\n"; } return nodeStr; }
From source file:Main.java
public static String getElementText(Element elem) { StringBuffer buf = new StringBuffer(); NodeList nodeList = elem.getChildNodes(); for (int i = 0, len = nodeList.getLength(); i < len; i++) { Node n = nodeList.item(i); if (n.getNodeType() == Node.TEXT_NODE) { buf.append(n.getNodeValue()); } else {// w ww.j av a 2 s. c om //TODO see jsf-samples //throw new FacesException("Unexpected node type " + n.getNodeType()); } } return buf.toString(); }
From source file:Main.java
public static String getTextForNode(Node node) { StringBuffer sb = new StringBuffer(); NodeList children = node.getChildNodes(); if (children.getLength() == 0) return null; for (int i = 0; i < children.getLength(); ++i) { Node n = children.item(i); if (n instanceof Text) sb.append(n.getNodeValue()); else if (n instanceof EntityReference) { String s = getTextForNode(n); if (s == null) return null; else/* w w w . j ava2s. c o m*/ sb.append(s); } else return null; } return sb.toString(); }
From source file:Main.java
/** * Extracts from node the attribute with the specified name. * @param node the node whose attribute we'd like to extract. * @param name the name of the attribute to extract. * @return a String containing the trimmed value of the attribute or null * if no such attribute exists/*from www . jav a 2s . co m*/ */ public static String getAttribute(Node node, String name) { if (node == null) return null; Node attribute = node.getAttributes().getNamedItem(name); return (attribute == null) ? null : attribute.getNodeValue().trim(); }
From source file:Main.java
/** * @return the attribute value or null// w w w . j a v a 2s. co m */ public static String getAttributeValue(Node node, String attributeName) { NamedNodeMap attributes = node.getAttributes(); if (attributes == null) return (null); Node tempNode = attributes.getNamedItem(attributeName); if (tempNode == null) return (null); return (tempNode.getNodeValue()); }
From source file:Main.java
/** * Returns the value of given node//w ww.j a v a2 s. c om * @param node node which value is to be returned * @return the value of given node */ public static String getNodeValue(Node node) { String retval = ""; try { Node firstChild = node.getFirstChild(); if (firstChild != null) retval = firstChild.getNodeValue(); } catch (Exception e) { return ""; } return retval; }
From source file:Utils.java
public static String getPrefix(Element el, String ns) { NamedNodeMap atts = el.getAttributes(); for (int i = 0; i < atts.getLength(); i++) { Node node = atts.item(i); String name = node.getNodeName(); if (ns.equals(node.getNodeValue()) && (name != null && (XMLNAMESPACE.equals(name) || name.startsWith(XMLNAMESPACE + ":")))) { return node.getPrefix(); }/*w ww. ja v a2 s. co m*/ } return null; }
From source file:Main.java
/** * /*from ww w .j a v a2 s . c o m*/ * @param node * @return String */ public static String getSimpleElementText(final Node node) { final NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node child = children.item(i); if (child instanceof Text) { return child.getNodeValue(); } } return null; }
From source file:Main.java
/** Return the text associated with a node, or <code>null</code> if no text section is present.//w w w. ja v a2 s . c om */ static public String getText(Node node) { if (node == null) return null; Node child = findChild(node, "#text"); if (child == null) return null; return child.getNodeValue(); }