users@saaj.java.net

[SAAJ-USR] SOAPElement#addChildElement() question?

From: Jongjin Choi <gunsnroz_at_hotmail.com>
Date: Tue, 15 Mar 2005 20:04:46 +0900

Hi,

I hava a question about SOAPElement#addChildElement().

With the following code,

SOAPMessage msg = MessageFactory.newInstance().createMessage();
SOAPEnvelope se = msg.getSOAPPart().getEnvelop();
SOAPBody sb = se.getBody();
SOAPElement sq = sb.addChildElement("getStockQuote", "ns1", "http://www.tempuri.org/stockquote"); // (1)
SOAPElement symbol = sq.addChildElement("symbol");
System.out.println("sq.getNamespaceURI() = " + sq.getNamespaceURI());
System.out.println("symbol.getNamespaceURI() = " + symbol.getNamespaceURI());
msg.writeTo(System.out);

The result is (I reformat SOAP message for readability) :
sq.getNamespaceURI() = http://www.tempuri.org/stockquote
symbol.getNamespaceURI() = null

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns1:getStockQuote xmlns:ns1="http://www.tempuri.org/stockquote">
<symbol>FOO</symbol>
</ns1:getStockQuote>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

So far so good, but I change (1) of the above code
SOAPElement sq = sb.addChildElement("getStockQuote", "", "http://www.tempuri.org/stockquote");

The result is :
sq.getNamespaceURI() = http://www.tempuri.org/stockquote
symbol.getNamespaceURI() = http://www.tempuri.org/stockquote

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<getStockQuote xmlns="http://www.tempuri.org/stockquote">
<symbol>FOO</symbol>
</getStockQuote>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
 
It's strange. I think the result should be (under soapbody):
<getStockQuote xmlns="http://www.tempuri.org/stockquote">
<symbol xmlns="">FOO</symbol>
</getStockQuote>

It seems that SOAPElement.addChildElement() behaves differently whether the parent element has prefix or not.
The SAAJ 1.2 spec is not clear about this. Is this a bug of currrent SAAJ impl or Is it intentional?

I tested it under SUN Java System Application Server PE8 2005Q1, but JWSDP 1.5 gives the same result.

Thanks.

/Jongjin Choi