Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.CharacterData;

import org.w3c.dom.Element;

import org.w3c.dom.Node;

public class Main {
    /**
     * Returns all child character data of the given element, including CDATA sections but NOT entity references.
     * @param parentEl the parent element.
     * @return the child character data of the element, or null if the element is null.
     */
    static public String getChildCharacterData(Element parentEl) {
        if (parentEl == null) {
            return null;
        }

        Node tempNode = parentEl.getFirstChild();
        StringBuffer strBuf = new StringBuffer();
        CharacterData charData;

        while (tempNode != null) {
            switch (tempNode.getNodeType()) {
            case Node.TEXT_NODE:
            case Node.CDATA_SECTION_NODE:
                charData = (CharacterData) tempNode;
                strBuf.append(charData.getData());
                break;
            //            case Node.ENTITY_REFERENCE_NODE : strBuf.append("&").append(tempNode.getNodeName()).append(";");

            }
            tempNode = tempNode.getNextSibling();
        }
        return strBuf.toString();
    }
}