List of usage examples for org.w3c.dom Text getLength
public int getLength();
data
and the substringData
method below. From source file:TreeDumper2.java
private void dumpTextNode(Text node, String indent) { System.out.println(indent + "TEXT length=" + node.getLength()); System.out.println(indent + " " + node.getData()); }
From source file:Counter.java
/** Traverses the specified node, recursively. */ public void count(Node node) { // is there anything to do? if (node == null) { return;// w ww . j a v a 2s . c o m } int type = node.getNodeType(); switch (type) { case Node.DOCUMENT_NODE: { fElements = 0; fAttributes = 0; fCharacters = 0; fIgnorableWhitespace = 0; Document document = (Document) node; count(document.getDocumentElement()); break; } case Node.ELEMENT_NODE: { fElements++; NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { fAttributes += attrs.getLength(); } // drop through to entity reference } case Node.ENTITY_REFERENCE_NODE: { Node child = node.getFirstChild(); while (child != null) { count(child); child = child.getNextSibling(); } break; } case Node.CDATA_SECTION_NODE: { fCharacters += ((Text) node).getLength(); break; } case Node.TEXT_NODE: { if (fDocumentInfo != null) { Text text = (Text) node; int length = text.getLength(); if (fDocumentInfo.isIgnorableWhitespace(text)) { fIgnorableWhitespace += length; } else { fCharacters += length; } } break; } } }