background image

SOAP envelope element

<< QName and SOAPElement | SOAPBody Element >>
<< QName and SOAPElement | SOAPBody Element >>
C
REATING AND
S
ENDING A
S
IMPLE
M
ESSAGE
129
Here is the XML it produces:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
. . .
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The outermost element in this XML example is the SOAP envelope element,
indicated by
SOAP-ENV:Envelope
. Note that
Envelope
is the name of the ele-
ment, and
SOAP-ENV
is the namespace prefix. The interface
SOAPEnvelope
repre-
sents a SOAP envelope.
The first line signals the beginning of the SOAP envelope element, and the last
line signals the end of it; everything in between is part of the SOAP envelope.
The second line is an example of an attribute for the SOAP envelope element.
Because a SOAP envelope element always contains 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. We 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 repre-
sents.
GetLastTradePrice
is its local name,
m
is its namespace prefix, and
http://wombat.ztrade.com
is its namespace URI.