Name

SOAPBodyElement

Synopsis

public interface SOAPBodyElement extends SOAPElement {
}

SOAPBodyElement is a subinterface of SOAPElement that represents an element that has been added directly to the body of a SOAP message. In all other respects, a SOAPBodyElement is the same as a SOAPElement.

The most direct way to create a SOAPBodyElement is to use the addBodyElement( ) method of SOAPBody, supplying the element name in the form of a Name object:

SOAPFacctory factory = SOAPFactory.newInstance();
Name elementName = factory.createName("BookSearch", "book", 
                                      "urn:BookService");
SOAPBodyElement bodyElement = soapBody.addBodyElement(elementName);
bodyElement.addTextNode("Java Web Services");

Since SOAPBody is itself a SOAPElement, it inherits its addChildElement( ) methods. It is therefore possible to use these methods to directly add elements to a SOAPBody like this:

SOAPElement element = body.addChildElement(
                                          "BookSearch", "book",                
                                             "urn:BookService");

This code actually creates a SOAPBodyElement rather than an ordinary SOAPElement. Additionally, SOAPElements created using factory methods and added directly to the SOAP body are replaced by SOAPBodyElements. Therefore, in the following code extract:

SOAPElement element = factory.createElement("BookSearch", "book", 
     "urn:BookService");
SOAPElement textElement = element.addTextNode("J2ME");
SOAPElement bodyElement = body.addChildElement(element);

the result of the addChildElement( ) method called on the third line is that a new SOAPBodyElement is created ...

Get Java Web Services in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.