Java XML Node to Element isElementContent(Node node)

Here you can find the source of isElementContent(Node node)

Description

Checks whether the specified node has element content or consists only of character data.

License

Apache License

Parameter

Parameter Description
node The node to test, may be <code>null</code>.

Return

true if any child node is an element, false otherwise.

Declaration

private static boolean isElementContent(Node node) 

Method Source Code

//package com.java2s;
/*/*from   ww  w .j  a v  a  2  s .c o m*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    /**
     * Checks whether the specified node has element content or consists only of character data.
     *
     * @param node The node to test, may be <code>null</code>.
     * @return <code>true</code> if any child node is an element, <code>false</code> otherwise.
     */
    private static boolean isElementContent(Node node) {
        if (node == null) {
            return false;
        }
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. isElement(Node node)
  2. isElement(Node node)
  3. isElement(Node node)
  4. isElement(Node node, String name)
  5. isElementByTag(Node node, String tagName)
  6. isElementNamed(Node node, String name)
  7. isElementNode(final Node target)
  8. isElementNode(Node n)
  9. isElementNode(Node n)