background image

SOAPBody

<< SOAPHeader | Getting a SOAPConnection Object >>
<< SOAPHeader | Getting a SOAPConnection Object >>

SOAPBody

this attribute with this value, a SOAPMessage object comes with it automatically included. xmlns
stands for "XML namespace," and its value is the URI of the namespace associated with
Envelope
.
The next line is an empty SOAP header. You could remove it by calling header.detachNode
after the getSOAPHeader call.
The next two lines mark the beginning and end of the SOAP body, represented in SAAJ by a
SOAPBody
object. The next step is to add content to the body.
Here is the SAAJ code:
QName bodyName = new QName(
"http://wombat.ztrade.com",
"GetLastTradePrice", "m");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
Here is the XML it produces:
<m:GetLastTradePrice
xmlns:m=
"http://wombat.ztrade.com">
...
</m:GetLastTradePrice>
These lines are what the SOAPBodyElement bodyElement in your code represents.
GetLastTradePrice
is its local name, m is its namespace prefix, and
http://wombat.ztrade.com
is its namespace URI.
Here is the SAAJ code:
QName name = new QName(
"symbol");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode(
"SUNW");
Here is the XML it produces:
<symbol>SUNW</symbol>
The String "SUNW" is the text node for the element <symbol>. This String object is the message
content that your recipient, the stock quote service, receives.
The following example shows how to add multiple SOAPElement objects and add text to each of
them. The code first creates the SOAPBodyElement object purchaseLineItems, which has a fully
qualified name associated with it. That is, the QName object for it has a namespace URI, a local
name, and a namespace prefix. As you saw earlier, a SOAPBodyElement object is required to have
a fully qualified name, but child elements added to it, such as SOAPElement objects, can have
Name
objects with only the local name.
SAAJ Tutorial
Chapter 19 · SOAP with Attachments API for Java
595