Example usage for javax.xml.soap SOAPElement getAttributes

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

Introduction

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

Prototype

public NamedNodeMap getAttributes();

Source Link

Document

A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.

Usage

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

@Validated
@Test// w ww. j a  v a2s .  co  m
public void testRemoveNamespaceDeclaration() throws SOAPException {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:p", "urn:ns");
    assertTrue(element.removeNamespaceDeclaration("p"));
    assertEquals(0, element.getAttributes().getLength());
}

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

@Validated
@Test/*from  w ww .j  a v  a2  s  .  c om*/
public void testRemoveAttributeByQNameNonExisting() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.setAttributeNS("urn:ns1", "ns1:attr", "value");
    assertFalse(element.removeAttribute(new QName("urn:ns2", "test")));
    NamedNodeMap attributes = element.getAttributes();
    assertEquals(1, attributes.getLength());
}

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

@Validated
@Test/*from w  w  w. ja  va2 s  . c om*/
public void testAddChildElementWithDeclaredNamespace() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:p", "urn:ns");
    SOAPElement child = element.addChildElement("test", "p", "urn:ns");
    assertEquals("urn:ns", child.getNamespaceURI());
    assertEquals("p", child.getPrefix());
    assertEquals("test", child.getLocalName());
    assertEquals(0, child.getAttributes().getLength());
}

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

/**
 * Tests the behavior of {@link SOAPElement#removeAttribute(QName)} for an attribute created
 * with {@link Element#setAttribute(String, String)}.
 * /*from   ww  w . ja v a  2s .c  o m*/
 * @throws Exception
 */
@Validated
@Test
public void testRemoveAttributeByQNameWithoutNamespace2() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.setAttributeNS("urn:ns1", "ns1:attr", "value");
    element.setAttribute("attr", "value");
    assertTrue(element.removeAttribute(new QName("attr")));
    NamedNodeMap attributes = element.getAttributes();
    assertEquals(1, attributes.getLength());
}

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

/**
 * Tests the behavior of {@link SOAPElement#removeAttribute(QName)} for an attribute created
 * with {@link Element#setAttributeNS(String, String, String)}, but without namespace.
 * //from w ww .j  a va  2  s. co m
 * @throws Exception
 */
@Validated
@Test
public void testRemoveAttributeByQNameWithoutNamespace1() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.setAttributeNS("urn:ns1", "ns1:attr", "value");
    element.setAttributeNS(null, "attr", "value");
    assertTrue(element.removeAttribute(new QName("attr")));
    NamedNodeMap attributes = element.getAttributes();
    assertEquals(1, attributes.getLength());
}

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

@Validated
@Test/*from   ww w  .j  a v  a2  s .  c  o  m*/
public void testRemoveAttributeByQNameWithNamespace() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.setAttributeNS("urn:ns1", "ns1:attr", "value");
    element.setAttributeNS("urn:ns2", "ns2:attr", "value");
    assertTrue(element.removeAttribute(new QName("urn:ns1", "attr")));
    NamedNodeMap attributes = element.getAttributes();
    assertEquals(1, attributes.getLength());
}

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

@Validated
@Test/*from  ww  w.j a  v a 2s  .c o m*/
public void testRemoveAttributeByName() throws Exception {
    SOAPEnvelope envelope = saajUtil.createSOAP11Envelope();
    SOAPBody body = envelope.addBody();
    SOAPElement element = body.addChildElement(new QName("urn:test", "test"));
    element.setAttributeNS("urn:ns1", "ns1:attr1", "value");
    element.setAttributeNS("urn:ns1", "ns1:attr2", "value");
    assertTrue(element.removeAttribute(envelope.createName("attr2", "p", "urn:ns1")));
    NamedNodeMap attributes = element.getAttributes();
    assertNull(attributes.getNamedItemNS("urn:ns1", "attr2"));
}