Sun Java System Message Queue 4.3 Developer's Guide for Java Clients

Using Namespaces when Creating a SOAP Name

When you create the body elements or header elements of a SOAP message, you must use the Name object to specify a well-formed name for the element. You obtain a Name object by calling the method SOAPEnvelope.createName.

When you call this method, you can pass a local name as a parameter or you can specify a local name, prefix, and URI. For example, the following line of code defines a name object bodyName.

Name bodyName = MyEnvelope.createName("TradePrice",

This would be equivalent to the namespace declaration:

<GetLTP:TradePrice xmlns:GetLTP= "">

The following code shows how you create a name and associate it with a SOAPBody element. Note the use and placement of the createName method.

SoapBody body = envelope.getBody();//get body from envelope
Name bodyName = envelope.createName("TradePrice", "GetLTP",
SOAPBodyElement gltp = body.addBodyElement(bodyName);