Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DocumentBuilderFactory docfactory=DocumentBuilderFactory.newInstance();
- docfactory.setIgnoringElementContentWhitespace(true);
- private static class NdLst implements NodeList, Iterable<Node> {
- private List<Node> nodes;
- public NdLst(NodeList list) {
- nodes = new ArrayList<Node>();
- for (int i = 0; i < list.getLength(); i++) {
- if (!isWhitespaceNode(list.item(i))) {
- nodes.add(list.item(i));
- }
- }
- }
- @Override
- public Node item(int index) {
- return nodes.get(index);
- }
- @Override
- public int getLength() {
- return nodes.size();
- }
- private static boolean isWhitespaceNode(Node n) {
- if (n.getNodeType() == Node.TEXT_NODE) {
- String val = n.getNodeValue();
- return val.trim().length() == 0;
- } else {
- return false;
- }
- }
- @Override
- public Iterator<Node> iterator() {
- return nodes.iterator();
- }
- }
Add Comment
Please, Sign In to add comment