Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.ArrayList;

import org.w3c.dom.Element;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static Node getSingleChildNode(Node p_node) throws Exception {

        NodeList l_list = null;
        Node l_node = null;
        ArrayList<Node> l_a = null;

        l_list = p_node.getChildNodes();
        if (l_list == null) {
            throw new Exception("XSD001: Unsupported / Invalid Element Type.");
        }
        l_a = new ArrayList<Node>();
        for (int l_i = 0; l_i < l_list.getLength(); l_i++) {
            l_node = l_list.item(l_i);
            if (l_node.getNodeType() == Element.ELEMENT_NODE) {
                l_a.add(l_node);
            }
        }
        if (l_a.size() == 1) {
            l_node = l_a.get(0);
        } else {
            throw new Exception("XSD003: Unsupported / Invalid Element Type Structure.");
        }

        return l_node;
    }
}