Java Reference
In-Depth Information
QName bodyName = new QName("http://example.com",
"getQuote", "e");
SOAPBodyElement bodyEl = body.addBodyElement(bodyName);
//Add our data
QName name = new QName("ticker");
SOAPElement ticker = bodyEl.addChildElement(name);
ticker.addTextNode("JAVA");
//to ticker element, add our countryCode attribute
//with a value of US
QName attributeName = new QName("countryCode");
ticker.addAttribute(attributeName, "US");
message.writeTo(System.out);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
As you can see, you've just created a QName for the attribute, passing it the name you want the
attribute to have. Then you specify its value when you add it to the ticker element.
Here is the resulting output:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<e:getQuote xmlns:e="http://example.com">
<ticker countryCode="US"> JAVA</ticker>
</e:getQuote>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The attribute has been added to your ticker element as shown in the highlighted code.
Search WWH ::




Custom Search