Example usage for org.w3c.dom Document removeChild

List of usage examples for org.w3c.dom Document removeChild

Introduction

In this page you can find the example usage for org.w3c.dom Document removeChild.

Prototype

public Node removeChild(Node oldChild) throws DOMException;

Source Link

Document

Removes the child node indicated by oldChild from the list of children, and returns it.

Usage

From source file:org.talend.mdm.webapp.browserecords.server.util.CommonUtil.java

public static Document parseResultDocument(String result, String expectedRootElement) throws Exception {
    Document doc = Util.parse(result);
    Element rootElement = doc.getDocumentElement();
    if (!rootElement.getNodeName().equals(expectedRootElement)) {
        // When there is a null value in fields, the viewable fields sequence is not enclosed by expected element
        // FIXME Better to find out a solution at the underlying stage
        doc.removeChild(rootElement);
        Element resultElement = doc.createElement(expectedRootElement);
        resultElement.appendChild(rootElement);
    }/* w  ww .  j ava 2  s .co  m*/
    return doc;
}

From source file:wssec.TestWSSecurityWSS234.java

/**
 * Test that signs and verifies a WS-Security envelope
 * <p/>// www.  j  a  v a  2 s  .  c om
 * 
 * @throws java.lang.Exception Thrown when there is any problem in signing or verification
 */
public void testSignature() throws Exception {
    WSSecSignature builder = new WSSecSignature();
    builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
    LOG.info("Before Signing....");
    Document doc = unsignedEnvelope.getAsDocument();
    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);
    Document signedDoc = builder.build(doc, crypto, secHeader);

    // Add a comment node as the first node element
    org.w3c.dom.Node firstChild = signedDoc.getFirstChild();
    org.w3c.dom.Node newNode = signedDoc.removeChild(firstChild);
    org.w3c.dom.Node commentNode = signedDoc.createComment("This is a comment");
    signedDoc.appendChild(commentNode);
    signedDoc.appendChild(newNode);

    if (LOG.isDebugEnabled()) {
        LOG.debug("After Signing....");
        String outputString = org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc);
        LOG.debug(outputString);
    }

    verify(signedDoc);
}