Java XML Child Get getChildElements(Element element)

Here you can find the source of getChildElements(Element element)

Description

get Child Elements

License

Open Source License

Declaration

public static List<Element> getChildElements(Element element) 

Method Source Code

//package com.java2s;
/**/* w w w . j a v  a2s .  com*/
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.ArrayList;
import java.util.List;

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

public class Main {
    public static List<Element> getChildElements(Element element) {
        NodeList nodeList = element.getChildNodes();

        List<Element> elements = new ArrayList<>(nodeList.getLength());

        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);

            if (node.getNodeType() == Node.ELEMENT_NODE) {
                Element childElement = (Element) node;

                boolean ignoreNode = false;

                NodeList childNodeList = childElement.getChildNodes();

                for (int j = 0; j < childNodeList.getLength(); j++) {
                    Node childNode = childNodeList.item(j);

                    if (childNode.getNodeType() == Node.TEXT_NODE) {
                        Text text = (Text) childNode;

                        String textContent = text.getTextContent();

                        if (textContent.contains("Ignore Dependency Comparison")) {
                            ignoreNode = true;

                            break;
                        }
                    }
                }

                if (!ignoreNode) {
                    elements.add(childElement);
                }
            }
        }

        return elements;
    }
}

Related

  1. getChildElements(Element element)
  2. getChildElements(Element element)
  3. getChildElements(Element element)
  4. getChildElements(Element element)
  5. getChildElements(Element element)
  6. getChildElements(Element element)
  7. getChildElements(Element element)
  8. getChildElements(Element parent)
  9. getChildElements(Element parent)