Example usage for javax.xml.soap SOAPElement hasAttributeNS

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

Introduction

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

Prototype

public boolean hasAttributeNS(String namespaceURI, String localName) throws DOMException;

Source Link

Document

Returns true when an attribute with a given local name and namespace URI 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);/*from  w w w.jav  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));
}