List of usage examples for org.w3c.dom Node TEXT_NODE
short TEXT_NODE
To view the source code for org.w3c.dom Node TEXT_NODE.
Click Source Link
Text
node. From source file:Main.java
public static String getText(Node node) { String value = ""; NodeList children = node.getChildNodes(); for (int k = 0; k < children.getLength(); k++) { Node child = children.item(k); if (child.getNodeType() == Node.TEXT_NODE) { value = child.getNodeValue(); }/* ww w . j a va 2 s. c o m*/ } return value; }
From source file:Main.java
public static String path(Node n) { if (n == null) return ""; switch (n.getNodeType()) { case Node.ATTRIBUTE_NODE: { return path(n.getParentNode()) + "/@" + n.getNodeName(); }// w w w. j av a 2 s . c om case Node.TEXT_NODE: { return path(n.getParentNode()) + "/text()"; } case Node.CDATA_SECTION_NODE: { return path(n.getParentNode()) + "/cdata()"; } case Node.ELEMENT_NODE: { return path(n.getParentNode()) + "/" + n.getNodeName(); } case Node.DOCUMENT_NODE: { return ""; } default: { return ""; } } }
From source file:Main.java
public static Node getFirstChildElement(Node node) { Node firstChildElement = null; for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { if (child.getNodeType() != Node.TEXT_NODE) { firstChildElement = child;/*from w w w . j ava 2 s . c o m*/ break; } } return firstChildElement; }
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() + " "; }// w ww. j av a 2 s . c o m } return text; }
From source file:Main.java
public static String getNodeText(Node node) { if (node == null) return null; StringBuffer buff = new StringBuffer(); for (int c = 0; c < node.getChildNodes().getLength(); c++) { Node cn = node.getChildNodes().item(c); if (cn.getNodeType() == Node.TEXT_NODE || cn.getNodeType() == Node.CDATA_SECTION_NODE) { buff.append(cn.getNodeValue()); }// w ww .ja v a 2s . c o m } return buff.toString().trim(); }
From source file:Main.java
public static String getDirectTextContent(Node aNode) { String result = ""; NodeList nodeList = aNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node aSubNode = nodeList.item(i); if (aSubNode.getNodeType() == Node.TEXT_NODE) { result += aSubNode.getNodeValue(); }// w w w . j a v a 2 s .c o m } return result; }
From source file:Main.java
public static String getValue(Element element) { NodeList l = element.getChildNodes(); StringBuffer s = new StringBuffer(); for (int i = 0; i < l.getLength(); i++) { switch (l.item(i).getNodeType()) { case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: s.append(l.item(i).getNodeValue()); }/*from ww w .j ava 2 s .c o m*/ } return s.toString(); }
From source file:Main.java
static public String getNodeValue(Node node) { NodeList childNodes = node.getChildNodes(); for (int x = 0; x < childNodes.getLength(); x++) { Node data = childNodes.item(x); if (data.getNodeType() == Node.TEXT_NODE) { return data.getNodeValue(); }//from w w w. java2s . co m } return ""; }
From source file:Main.java
/** Decide if the node is text, and so must be handled specially */ public static boolean isTextNode(final Node n) { if (n == null) { return false; }/*from ww w .j av a 2 s . c o m*/ short nodeType = n.getNodeType(); return nodeType == Node.CDATA_SECTION_NODE || nodeType == Node.TEXT_NODE; }
From source file:Main.java
public static String getTextData(Node node) { if (!node.hasChildNodes()) { return null; }// w ww .j ava 2 s . co m Node child = node.getFirstChild(); while (child != null && child.getNodeType() != Node.TEXT_NODE && child.getNodeType() != Node.CDATA_SECTION_NODE) { child = child.getNextSibling(); } if (child == null) { return null; } if (child.getNodeType() == Node.TEXT_NODE) { return ((Text) child).getData(); } else { return ((CDATASection) child).getData(); } }