Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.*;
import org.w3c.dom.*;

public class Main {
    /**
     * Extracts a bunch of notes from an <code>Element</code>
     */
    protected static List<String> extractNotesFrom(Element element) {
        List<String> list = new ArrayList<String>();

        NodeList children = element.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node node = children.item(i);
            if (!(node instanceof Element)) {
                continue;
            }

            Element child = (Element) node;
            if (child.getTagName().equals("note")) {
                list.add(extractTextFrom(child));
            }
        }

        return list;
    }

    /**
     * Extracts the text from an <code>Element</code>.
     */
    protected static String extractTextFrom(Element element) {
        Text text = (Text) element.getFirstChild();
        return (text == null ? "" : text.getData());
    }
}