Here you can find the source of isElementContent(Node node)
Parameter | Description |
---|---|
node | The node to test, may be <code>null</code>. |
true
if any child node is an element, false
otherwise.
private static boolean isElementContent(Node node)
//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; } }