SOAPBodyElement | javax.xml.soap |
SAAJ 1.1; JWSDP 1.0, J2EE 1.4 |
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, SOAPElement s created using factory methods and added directly to the SOAP body are replaced by SOAPBodyElement s. 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 and added to the body in place of the original element and a reference to that SOAPBodyElement is returned. Any elements below the original element (in this case, the Text node) are copied and placed below the newly created SOAPBodyElement .
SOAPFault
SOAPBody.addBodyElement( )