Example usage for javax.xml.soap SOAPElement removeContents

List of usage examples for javax.xml.soap SOAPElement removeContents

Introduction

In this page you can find the example usage for javax.xml.soap SOAPElement removeContents.

Prototype

public abstract void removeContents();

Source Link

Document

Detaches all children of this SOAPElement .

Usage

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

@Validated
@Test/*from   w  w w . ja  v a2s.co  m*/
public void testRemoveContents() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.addChildElement(new QName("child1"));
    element.addChildElement(new QName("child2"));
    element.removeContents();
    assertNull(element.getFirstChild());
}

From source file:org.jbpm.bpel.integration.soap.SoapUtil.java

public static void copy(SOAPElement target, Element source) throws SOAPException {
    if (traceEnabled)
        log.trace("copying from: " + XmlUtil.toTraceString(source));
    // attributes
    removeAttributes(target);/*w ww.  j  av a2s  .c  om*/
    copyAttributes(target, source);
    // all namespaces
    removeNamespaces(target);
    copyVisibleNamespaces(target, source);
    ensureOwnNamespaceDeclared(target);
    // child nodes
    target.removeContents();
    copyChildNodes(target, source);
    if (traceEnabled)
        log.trace("copied to: " + XmlUtil.toTraceString(target));
}

From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java

public void testRemoveChildNodes_soap() throws Exception {
    String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>"
            + " <soap:Body xmlns:fish='urn:example:fish'>" + "  <meal:lunch xmlns:produce='urn:example:produce'"
            + "   xmlns:meal='urn:example:meal'>" + "   <time>1200</time>"
            + "   <produce:lettuce>0.1lb</produce:lettuce>"
            + "   <fish:fillet xmlns:fish='urn:example:fish'>0.25lb</fish:fillet>" + "  </meal:lunch>"
            + " </soap:Body>" + "</soap:Envelope>";
    ByteArrayInputStream sourceStream = new ByteArrayInputStream(xml.getBytes());
    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, sourceStream);
    SOAPElement element = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:meal", "lunch");
    // remove the child nodes
    element.removeContents();
    // verify remotion
    assertFalse(element.getChildElements().hasNext());
}