Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.*;

public class Main {
    /**
     * Gets all the text child nodes of an {@link Element} and coalesces them
     * together into one string.
     *
     * @param parent The {@link Element} to get the text child nodes of.
     * @return Returns the coalesced text.
     */
    public static String getCoalescedTextChildrenOf(Element parent) {
        final StringBuilder buf = new StringBuilder();
        final NodeList children = parent.getChildNodes();
        final int numChildren = children.getLength();
        for (int i = 0; i < numChildren; ++i) {
            final Node child = children.item(i);
            if (child instanceof Text)
                buf.append(((CharacterData) child).getData());
        }
        return buf.toString();
    }
}