Java XML Node Text Value addElementText(Node test, List holder)

Here you can find the source of addElementText(Node test, List holder)

Description

add Element Text

License

Apache License

Declaration

protected static void addElementText(Node test, List holder) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.*;

import java.util.*;

public class Main {
    protected static void addElementText(Node test, List holder) {
        int Type = test.getNodeType();
        switch (Type) {
        case Node.CDATA_SECTION_NODE:
        case Node.TEXT_NODE:
            String text = test.getNodeValue();
            if (isAlphaString(text))
                holder.add(text);//from  ww w  .  j ava 2s . c  o m
            return;
        case Node.ELEMENT_NODE:
            accumulateElementText((Element) test, holder);
        default:
            Type = 0;
        }
    }

    public static boolean isAlphaString(String s) {
        if (s == null)
            return (false);
        for (int i = 0; i < s.length(); i++) {
            if (Character.isLetterOrDigit(s.charAt(i)))
                return (true);
        }
        return (false);
    }

    /**
    retrieve all Strings from this node
     */
    public static void accumulateElementText(Element doc, List holder) {
        NodeList nodes = doc.getChildNodes();
        int n = nodes.getLength();
        for (int i = 0; i < n; i++) {
            addElementText(nodes.item(i), holder);
        }
    }
}

Related

  1. createNewTextElement(Node elem, String tag, String value)
  2. existNode(Node node, String nodeName, String textValue)
  3. extractNodeText(Node node)
  4. extractText(Node node)