List of usage examples for javax.xml.soap SOAPElement getAttributeNodeNS
public Attr getAttributeNodeNS(String namespaceURI, String localName) throws DOMException;
Attr
node by local name and namespace URI. From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test//ww w . ja va 2s. com public void testAddAttributeFromQNameWithoutNamespace() throws Exception { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); SOAPElement retValue = element.addAttribute(new QName("attr"), "value"); assertSame(element, retValue); Attr attr = element.getAttributeNodeNS(null, "attr"); assertNull(attr.getNamespaceURI()); String localName = attr.getLocalName(); // The RI creates a namespace unaware attribute node in this case; we believe // it's better to create a namespace aware node. if (localName != null) { assertEquals("attr", attr.getLocalName()); } assertNull(attr.getPrefix()); assertEquals("value", attr.getValue()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test/*from w w w. ja v a 2 s .c o m*/ public void testAddAttributeFromQNameWithNamespace() throws Exception { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); SOAPElement retValue = element.addAttribute(new QName("urn:ns", "attr", "p"), "value"); assertSame(element, retValue); Attr attr = element.getAttributeNodeNS("urn:ns", "attr"); assertEquals("urn:ns", attr.getNamespaceURI()); assertEquals("attr", attr.getLocalName()); assertEquals("p", attr.getPrefix()); assertEquals("value", attr.getValue()); Attr nsDecl = element.getAttributeNodeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "p"); assertNotNull(nsDecl); assertEquals("urn:ns", nsDecl.getValue()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test/*from www . java 2 s . c o m*/ public void testAddAttributeFromNameWithoutNamespace() throws Exception { SOAPEnvelope envelope = saajUtil.createSOAP11Envelope(); SOAPBody body = envelope.addBody(); SOAPElement element = body.addChildElement(new QName("urn:test", "test")); SOAPElement retValue = element.addAttribute(envelope.createName("attr"), "value"); assertSame(element, retValue); Attr attr = element.getAttributeNodeNS(null, "attr"); assertNull(attr.getNamespaceURI()); String localName = attr.getLocalName(); if (localName != null) { assertEquals("attr", attr.getLocalName()); } assertNull(attr.getPrefix()); assertEquals("value", attr.getValue()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test// ww w .j a v a 2 s. c om public void testAddAttributeFromNameWithNamespace() throws Exception { SOAPEnvelope envelope = saajUtil.createSOAP11Envelope(); SOAPBody body = envelope.addBody(); SOAPElement element = body.addChildElement(new QName("urn:test", "test")); SOAPElement retValue = element.addAttribute(envelope.createName("attr", "p", "urn:ns"), "value"); assertSame(element, retValue); Attr attr = element.getAttributeNodeNS("urn:ns", "attr"); assertEquals("urn:ns", attr.getNamespaceURI()); assertEquals("attr", attr.getLocalName()); assertEquals("p", attr.getPrefix()); assertEquals("value", attr.getValue()); Attr nsDecl = element.getAttributeNodeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "p"); assertNotNull(nsDecl); assertEquals("urn:ns", nsDecl.getValue()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test//from www.j a va 2 s . c o m public void testAddChildElementWithUndeclaredNamespace() throws Exception { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); SOAPElement child = element.addChildElement("test", "p", "urn:ns"); assertEquals("urn:ns", child.getNamespaceURI()); assertEquals("p", child.getPrefix()); assertEquals("test", child.getLocalName()); Attr nsDecl = child.getAttributeNodeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "p"); assertNotNull(nsDecl); assertEquals("urn:ns", nsDecl.getValue()); }
From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java
/** * add attributes/*from www . j a v a 2 s . co m*/ * * @param NameCreator nc * @param element SOAPElement which is the target of the new attributes * @param reader XMLStreamReader whose cursor is at START_ELEMENT * @throws SOAPException */ protected void addAttributes(NameCreator nc, SOAPElement element, XMLStreamReader reader) throws SOAPException { if (log.isDebugEnabled()) { log.debug("addAttributes: Entry"); } // Add the attributes from the reader int size = reader.getAttributeCount(); for (int i = 0; i < size; i++) { QName qName = reader.getAttributeName(i); String prefix = reader.getAttributePrefix(i); String value = reader.getAttributeValue(i); Name name = nc.createName(qName.getLocalPart(), prefix, qName.getNamespaceURI()); element.addAttribute(name, value); try { if (log.isDebugEnabled()) { log.debug("Setting attrType"); } String namespace = qName.getNamespaceURI(); Attr attr = null; // This is an org.w3c.dom.Attr if (namespace == null || namespace.length() == 0) { attr = element.getAttributeNode(qName.getLocalPart()); } else { attr = element.getAttributeNodeNS(namespace, qName.getLocalPart()); } if (attr != null) { String attrType = reader.getAttributeType(i); attr.setUserData(SAAJConverter.OM_ATTRIBUTE_KEY, attrType, null); if (log.isDebugEnabled()) { log.debug("Storing attrType in UserData: " + attrType); } } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("An error occured while processing attrType: " + e.getMessage()); } } } if (log.isDebugEnabled()) { log.debug("addAttributes: Exit"); } }