Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.w3c.dom.Element;

import org.w3c.dom.Node;

public class Main {
    public static Element getParentXElement(Element startElement, String xmlTag) {
        boolean found = false;
        if (startElement == null)
            return null;
        Node parentNode = startElement.getParentNode();
        while (!found) {
            if (parentNode == null)
                found = true;
            else if (parentNode.getNodeName().equals(xmlTag))
                found = true;
            if (!found)
                parentNode = parentNode.getParentNode();
        }
        return (Element) parentNode;
    }
}