Example usage for javax.xml.soap SOAPElement hasAttribute

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

Introduction

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

Prototype

public boolean hasAttribute(String name);

Source Link

Document

Returns true when an attribute with a given name is specified on this element or has a default value, false otherwise.

Usage

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

public void testRemoveAttributes_soap() throws Exception {
    String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>"
            + " <soap:Body xmlns:fish='urn:example:fish'>"
            + "  <lunch time='1200' produce:lettuce='0.1lb' fish:fillet='0.25lb' "
            + "   xmlns:produce='urn:example:produce' />" + " </soap:Body>" + "</soap:Envelope>";
    ByteArrayInputStream sourceStream = new ByteArrayInputStream(xml.getBytes());
    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, sourceStream);
    SOAPElement element = SoapUtil.getElement(soapMessage.getSOAPBody(), "lunch");
    // remove the attributes
    SoapUtil.removeAttributes(element);//ww w . ja v a 2  s  .co  m
    // verify remotion with the dom & saaj apis
    assertFalse(element.hasAttribute("time"));
    assertFalse(element.hasAttributeNS("urn:example:produce", "lettuce"));
    assertFalse(element.hasAttributeNS("urn:example:fish", "fillet"));
    // namespaces should still be there
    // prefixed declaration
    assertEquals("produce", SoapUtil.getPrefix("urn:example:produce", element));
    // parent prefixed declaration
    assertEquals("fish", SoapUtil.getPrefix("urn:example:fish", element));
}