Java Code Examples for org.w3c.dom.Node.removeChild()

The following are Jave code examples for showing how to use removeChild() of the org.w3c.dom.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: Schema2BeansUtil.java   Source Code and License Vote up 7 votes
/**
 * Merge child nodes
 * 
 * @param node     current node base
 * @param childNode child node if exist
 * @param foundBean child bean
 * @param currentChild current child node
 * @param patternChild current pattern child
 * @param nodeMap node map
 * @param document document
 * @param patternBean pattern bean
 * @param children list relevant childs current node base
 */
private static void mergeChildNodes(Node node, Node childNode, BaseBean foundBean,
        Node currentChild, Node patternChild, Map nodeMap, Document document,
        BaseBean patternBean, List children) {
    Node foundChild = childNode;
    if (foundChild == null) {
        foundChild = takeEqualNode(children, patternChild);
    }
    if (foundChild != null) {
        if (foundChild != currentChild) {
            node.removeChild(foundChild);
            node.insertBefore(foundChild, currentChild);
        }
        if (foundBean != null) {
            mergeBeans(nodeMap, foundBean, patternBean);
        } else if (isRelevantNode(foundChild) && foundChild.hasChildNodes()) {
            mergeNode(nodeMap, foundChild, patternChild);
        } else {
            foundChild.setNodeValue(patternChild.getNodeValue());
        }
    } else {
        Node child = document.importNode(patternChild, true);
        node.insertBefore(child, currentChild);
    }
}
 
Example 2
Project: incubator-netbeans   File: GenerateJnlpFileTask.java   Source Code and License Vote up 6 votes
private void processSecurityElem(Document docDom, Node parent) {
    NodeList childNodes = parent.getChildNodes();
    int len = childNodes.getLength();
    for (int i = 0; i < len; i++) {
        Node node = childNodes.item(i);
        if (node != null && node.getNodeType() == Node.COMMENT_NODE) { // node might be null (don't know why)
            if (node.getNodeValue().equals(DEFAULT_JNLP_SECURITY)) {
                String securityProp = getProperty("jnlp.signed", null); //NOI18N // property in project.properties
                if (securityProp != null && securityProp.equalsIgnoreCase("true")) { //NOI18N
                    parent.replaceChild(createSecurityElement(docDom), node);
                } else {
                    parent.removeChild(node);
                }
            }
        }
    }
}
 
Example 3
Project: ccpa   File: TreeOptimizer.java   Source Code and License Vote up 6 votes
private static void removeNoOps(Node program)
{
	NodeList statements = program.getChildNodes();
	for (int i = 0; i < statements.getLength(); i++)
	{
		Node statement = statements.item(i);
		int oldLength = statements.getLength();
		if (statement.getNodeName().equals("op"))
		    removeNoOpsFromOp(program,statement);
		else if (statement.getNodeName().equals("value"))
			program.removeChild(statement);
		if (oldLength > statements.getLength()){
			i = -1;
		}
	}
}
 
Example 4
Project: OpenJSharp   File: ElementImpl.java   Source Code and License Vote up 6 votes
public void removeContents() {
    Node currentChild = getFirstChild();

    while (currentChild != null) {
        Node temp = currentChild.getNextSibling();
        if (currentChild instanceof javax.xml.soap.Node) {
            ((javax.xml.soap.Node) currentChild).detachNode();
        } else {
            Node parent = currentChild.getParentNode();
            if (parent != null) {
                parent.removeChild(currentChild);
            }

        }
        currentChild = temp;
    }
}
 
Example 5
Project: ccpa   File: TreeOptimizer.java   Source Code and License Vote up 6 votes
private static void removeUnusedVariables(Node program)
{
	NodeList statements = program.getChildNodes();
	for (int i = 0; i < statements.getLength(); i++)
	{
		Node statement = statements.item(i);
		if (statement.getNodeName().equals("uses"))
		{
		    if (variableNotUsed(program,statement.getChildNodes().item(1)))
		    {
		    	program.removeChild(statement);
		    	i = -1;
		    }
		}
		else if (statement.getNodeName().equals("op"))
		{
			removeUnusedVariables(statement);
		}
	}
}
 
Example 6
Project: openjdk-jdk10   File: ElementImpl.java   Source Code and License Vote up 6 votes
@Override
public void removeContents() {
    Node currentChild = getFirstChild();

    while (currentChild != null) {
        Node temp = currentChild.getNextSibling();
        if (currentChild instanceof javax.xml.soap.Node) {
            ((javax.xml.soap.Node) currentChild).detachNode();
        } else {
            Node parent = currentChild.getParentNode();
            if (parent != null) {
                parent.removeChild(currentChild);
            }

        }
        currentChild = temp;
    }
}
 
Example 7
Project: xmlrss   File: AbstractXMLRSSTest.java   Source Code and License Vote up 6 votes
@Test
public void testVerifyFalseModfiedSig() throws Exception {
    RedactableXMLSignature sig = RedactableXMLSignature.getInstance(algorithm);
    sig.initSign(keyPair);
    sig.setDocument(new FileInputStream("testdata/vehicles.xml"));
    sig.addSignSelector("#xpointer(id('a1'))", true);
    sig.addSignSelector("#xpointer(id('a2'))", true);
    sig.addSignSelector("#xpointer(id('a3'))", true);
    Document document = sig.sign();
    printDocument(document);

    Node proof = document.getElementsByTagName("Proof").item(0);
    proof.removeChild(proof.getFirstChild());

    sig.initVerify(keyPair.getPublic());
    sig.setDocument(document);
    try {
        assertFalse(sig.verify());
    } catch (Exception e) {
        assertTrue(true);
    }
    validateXSD(document);
}
 
Example 8
Project: jdk8u-jdk   File: DOMUtils.java   Source Code and License Vote up 5 votes
/**
 * Removes all children nodes from the specified node.
 *
 * @param node the parent node whose children are to be removed
 */
public static void removeAllChildren(Node node) {
    NodeList children = node.getChildNodes();
    for (int i = 0, length = children.getLength(); i < length; i++) {
        node.removeChild(children.item(i));
    }
}
 
Example 9
Project: incubator-netbeans   File: Schema2BeansUtil.java   Source Code and License Vote up 5 votes
/**
 * Merge "unsupported" attributes and child elements of node
 *
 * @param nodeMap
 * @param node
 * @param patternNode
 */
private static void mergeNode(Map nodeMap, Node node, Node patternNode) {
    mergeAttributes(node, patternNode);
    NodeList childNodes = node.getChildNodes();
    List children = relevantNodes(childNodes);
    Document document = getOwnerDocument(node);
    for (int i = childNodes.getLength() - 1; i >= 0; i--) {//remove all comments and break lines from current document node
        Node childNode = childNodes.item(i);
        if (!isRelevantNode(childNode)) {
            node.removeChild(childNode);
        }
    }
    NodeList patternChildNodes = patternNode.getChildNodes();
    for (int i = 0; i < patternChildNodes.getLength(); i++) {
        Node patternChild = patternChildNodes.item(i);
        Node currentChild = childNodes.item(i);
        if (isRelevantNode(patternChild)) {
            BaseBean patternBean = (BaseBean) nodeMap.get(patternChild);
            BaseBean foundBean;
            Node foundChild;
            if (patternBean != null) {
                foundBean = takeEqualBean(nodeMap, children, patternBean);
                foundChild = foundBean == null ? null : foundBean.binding.getNode();
            } else {
                foundBean = null;
                foundChild = null;
            }
            mergeChildNodes(node, foundChild, foundBean, currentChild, patternChild, nodeMap, document, patternBean, children);
        } else {
            mergeChildNodes(node, null, null, currentChild, patternChild, nodeMap, document, null, children);
        }
    }
}
 
Example 10
Project: Hydrograph   File: ParseExternalElements.java   Source Code and License Vote up 5 votes
private void removeExpressionNodes(Node parent) {
	for (int i = 0; i < parent.getChildNodes().getLength(); i++) {
		if (parent.getChildNodes().item(i).getNodeName().equals(INCLUDE_EXTERNAL_EXPRESSION) || parent.getChildNodes().item(i).getNodeName().equals(EXPRESSION)) {
			parent.removeChild(parent.getChildNodes().item(i));
		}
	}
}
 
Example 11
Project: EspressoViews   File: QueryDefinitionParser.java   Source Code and License Vote up 5 votes
public static void storeFileLocator (LinkedList<String> storedFileLocators, String iniFile ){
	Document doc= getXmlDocument(iniFile);
//	doc.getElementsByTagName(arg0)
	//System.out.println(storedFileLocators);
	Node fileLocatorNode = getElementByTagName (doc,"DEFINITIONFILELOCATORS");
	boolean tagUpdated=false;
	for (String fileLocator: storedFileLocators){//check if the file locator list contains file locator which are not stored in the ini setting 
	boolean fileLocatorIsStored=false; 
		for (int t = 0; t<fileLocatorNode.getChildNodes().getLength(); t++){
			 	if ( fileLocator.equals(fileLocatorNode.getChildNodes().item(t).getTextContent()) )
			 		fileLocatorIsStored=true;  
			 }
		if (!fileLocatorIsStored) {
			for (int tt = 0; tt<fileLocatorNode.getChildNodes().getLength(); tt++){
			 	if (fileLocatorNode.getChildNodes().item(tt).getNodeType()==1 ) 
			 		doc.renameNode( fileLocatorNode.getChildNodes().item(tt)
			 				,null,
			 				"FileLocator"+String.valueOf(Integer.valueOf(fileLocatorNode.getChildNodes().item(tt).getNodeName().substring(11))+1)  ); 
			 }
			Stack<Node> nodeStapel = new Stack<Node>(); 
			int childrenCount = fileLocatorNode.getChildNodes().getLength();
			for (int ttt = 0; ttt<childrenCount; ttt++){
			if (fileLocatorNode.getChildNodes().item( fileLocatorNode.getChildNodes().getLength()-1 ).getNodeType() == 1)//
				nodeStapel.push(fileLocatorNode.getChildNodes().item( fileLocatorNode.getChildNodes().getLength()-1 ));//Immer wird der Letzte genommen und auf dem Stack gesetzt, damit wird das letzte Kind auch das Letze in der neuen Reihe sein 
			fileLocatorNode.removeChild(fileLocatorNode.getChildNodes().item( fileLocatorNode.getChildNodes().getLength()-1 )); 
			//wird ein Kind removed und er hintel�sst danach eine Index-L�cke, wird die Kinder-Indexierung neu vergeben und das alte Kind 1 wird Kind 0  
			}
			Element neuesElement = doc.createElement("FileLocator0");
			neuesElement.appendChild(doc.createTextNode(fileLocator)  );
//			fileLocatorNode.appendChild(neuesElement);
			nodeStapel.push( neuesElement );//das neueste Element wird der erste FileLocator-tag sein  
			tagUpdated=true;
			childrenCount=1;
			while (!nodeStapel.isEmpty()&&childrenCount<=10){
				fileLocatorNode.appendChild(nodeStapel.pop());
				childrenCount++;
			}				
			//showMeTheDoc(fileLocatorNode, 0);
		}
	}
if (tagUpdated){
storeXmlDocToFile(iniFile, doc); 	  
 }
}
 
Example 12
Project: oscm   File: MigrationBillingResultRemoveSubscriptionCost.java   Source Code and License Vote up 5 votes
protected String migrateBillingResultXml(String billingXml)
        throws Exception {
    Document document = XMLConverter.convertToDocument(billingXml, false);
    NodeList subscriptionCosts = findSubscriptionCost(document);
    for (int i = 0; i < subscriptionCosts.getLength(); i++) {
        Node subscriptionCost = subscriptionCosts.item(i);
        Node parent = subscriptionCost.getParentNode();
        parent.removeChild(subscriptionCost);
    }
    return XMLConverter.convertToString(document, false);
}
 
Example 13
Project: OpenJSharp   File: ElementImpl.java   Source Code and License Vote up 5 votes
public void detachNode() {
    Node parent = getParentNode();
    if (parent != null) {
        parent.removeChild(this);
    }
    encodingStyleAttribute.clearNameAndValue();
    // Fix for CR: 6474641
    //tryToFindEncodingStyleAttributeName();
}
 
Example 14
Project: Hydrograph   File: ParseSubjob.java   Source Code and License Vote up 5 votes
private void removeSubjobComponentFromParentjob(Document XmlDocument,
		String subjobId) {
	NodeList nodeList = XmlDocument.getFirstChild().getChildNodes();
	for (int i = 0; i < nodeList.getLength(); i++) {
		if (nodeList.item(i).getNodeName().matches(SUBJOB_COMPONENTS)) {
			String componentId = nodeList.item(i).getAttributes()
					.getNamedItem(ID).getNodeValue();
			if (componentId.equals(subjobId)) {
				Node parent = nodeList.item(i).getParentNode();
				parent.removeChild(nodeList.item(i));
			}
		}
	}
}
 
Example 15
Project: Cognizant-Intelligent-Test-Scripter   File: XMLOperation.java   Source Code and License Vote up 5 votes
public static void removeAll(Node node) {
    NodeList list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        Node n = list.item(i);
        if (n.hasChildNodes()) {
            removeAll(n);
            node.removeChild(n);
        } else {
            node.removeChild(n);
        }
    }
}
 
Example 16
Project: Equella   File: ReplaceDeletedControlsXmlMigration.java   Source Code and License Vote up 5 votes
private static void switcheroo(XmlDocument xml, String nodeToSwitch, Node newParent, Node oldParent)
{
	Node newNode = xml.node(nodeToSwitch, newParent);
	if( newNode != null )
	{
		newParent.removeChild(newNode);
	}
	final Node oldNode = xml.node(nodeToSwitch, oldParent);
	if( oldNode != null )
	{
		newParent.appendChild(oldNode);
	}
}
 
Example 17
Project: OpenJSharp   File: AbstractDOMParser.java   Source Code and License Vote up 4 votes
/**
 * The end of a CDATA section.
 * @param augs     Additional information that may include infoset augmentations
 *
 * @throws XNIException Thrown by handler to signal an error.
 */
public void endCDATA (Augmentations augs) throws XNIException {

    fInCDATASection = false;
    if (!fDeferNodeExpansion) {

        if (fFilterReject) {
            return;
        }

        if (fCurrentCDATASection !=null) {

            if (fDOMFilter !=null && !fInEntityRef &&
            (fDOMFilter.getWhatToShow () & NodeFilter.SHOW_CDATA_SECTION)!= 0) {
                short code = fDOMFilter.acceptNode (fCurrentCDATASection);
                switch (code) {
                    case LSParserFilter.FILTER_INTERRUPT:{
                        throw Abort.INSTANCE;
                    }
                    case LSParserFilter.FILTER_REJECT:{
                        // fall through to SKIP since CDATA section has no children.
                    }
                    case LSParserFilter.FILTER_SKIP: {
                        Node parent = fCurrentNode.getParentNode ();
                        parent.removeChild (fCurrentCDATASection);
                        fCurrentNode = parent;
                        return;
                    }

                    default: {
                        // accept node
                    }
                }
            }

            fCurrentNode = fCurrentNode.getParentNode ();
            fCurrentCDATASection = null;
        }
    }
    else {
        if (fCurrentCDATASectionIndex !=-1) {
            fCurrentNodeIndex =
            fDeferredDocumentImpl.getParentNode (fCurrentNodeIndex, false);
            fCurrentCDATASectionIndex = -1;
        }
    }

}
 
Example 18
Project: convertigo-engine   File: XMLUtils.java   Source Code and License Vote up 4 votes
public static void removeChilds(Node node) {
	NodeList nl = node.getChildNodes();
	for (int i = 0; i < nl.getLength(); i++)
		node.removeChild(nl.item(i));
}
 
Example 19
Project: openjdk-jdk10   File: RangeImpl.java   Source Code and License Vote up 4 votes
Node removeChild(Node parent, Node child) {
    fRemoveChild = child;
    Node n = parent.removeChild(child);
    fRemoveChild = null;
    return n;
}
 
Example 20
Project: OpenJSharp   File: XMLCipher.java   Source Code and License Vote up 4 votes
/**
 * Removes the contents of a <code>Node</code>.
 *
 * @param node the <code>Node</code> to clear.
 */
private static void removeContent(Node node) {
    while (node.hasChildNodes()) {
        node.removeChild(node.getFirstChild());
    }
}