Here you can find the source of removeTextNodes(Node parent)
Parameter | Description |
---|---|
parent | the parent |
private static Node removeTextNodes(Node parent)
//package com.java2s; /**//from w w w.j av a 2 s . co m * This document is a part of the source code and related artifacts * for CollectionSpace, an open source collections management system * for museums and related institutions: * http://www.collectionspace.org * http://wiki.collectionspace.org * Copyright 2009 University of California at Berkeley * Licensed under the Educational Community License (ECL), Version 2.0. * You may not use this file except in compliance with this License. * You may obtain a copy of the ECL 2.0 License at * https://source.collectionspace.org/collection-space/LICENSE.txt * 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 { /** * Removes all the immediate child text nodes. * * @param parent * the parent * @return the element */ private static Node removeTextNodes(Node parent) { Node result = parent; NodeList nodeList = parent.getChildNodes(); int nodeListSize = nodeList.getLength(); for (int i = 0; i < nodeListSize; i++) { Node child = nodeList.item(i); if (child != null && child.getNodeType() == Node.TEXT_NODE) { parent.removeChild(child); } } return result; } }