[jdom-interest] [Q]namespace in SOAPHeader by JDOM and org.w3c way

Itoh, Kazuhiro kazuhiro-i at kajima.com
Thu Dec 5 00:05:01 PST 2002


Hello All
This is Kazu from Japan....

I made a small web service using
Apache AXIS(1.1beta) on Apache Tomcat 4.1.10, JDOM beta 8 , JDK1.4.1 and
Windows2000SP3.
Then I met small difference in SOAP header by two methods.

When I created SOAP Header, I used two way.

Way-1
1 Created org.jdom.Element for SOPA Header.
2 Next transfred it to org.w3c.Element using org.jdom.out.Domoutputter
3 Finally, set org.w3c.Element to SOAP Header

Then I got request SOAP header like this
 <soapenv:Header>
     <ns1:EMail xmlns="http://www.foo.bar.com"
xmlns:ns1="http://www.foo.bar.com">
        null at null.com
     </ns1:EMail>
 </soapenv:Header>

"http://www.foo.bar.com" is namespace in the originall Documnet. 
But there are two declarations in EMail element.
The namespace ns1 is created by AXIS.

Way-2
Not using JDOM API, but using w3c.dom.XXXX

I got the following header:

 <soapenv:Header>
    <ns1:EMail
xmlns:ns1="http://www.foo.bar.com">null at null.com</ns1:EMail>
 </soapenv:Header>

There is only one namespace declaration from original declaration.

I have no idea on this difference.
Is ther any information about this?

Please refer to the code snipet..

Way-1
---------------------------------- start
------------------------------------
    SOAPEnvelope reqEnv = new SOAPEnvelope();

    //create SOAP Header using JDOM
    Namespace ns =
Namespace.getNamespace("http://www.foo.bar.com");//Default NameSpace
    Element emailElm = new Element("EMail", ns);
    emailElm.addContent(this.email);
    DOMOutputter dout = new DOMOutputter();
    org.w3c.dom.Element emailElem =  dout.output(emailElm);
    
    reqEnv.addHeader(new SOAPHeaderElement(emailElem));
---------------------------------- end
------------------------------------

Way-2
---------------------------------- start
------------------------------------
    SOAPEnvelope reqEnv = new SOAPEnvelope();

    // using pure org.w3c......
    javax.xml.parsers.DocumentBuilderFactory bf =
javax.xml.parsers.DocumentBuilderFactory.newInstance();
    javax.xml.parsers.DocumentBuilder db = bf.newDocumentBuilder();
    org.w3c.dom.Document doc = db.newDocument();
    org.w3c.dom.Element emailElem =
doc.createElementNS("http://www.foo.bar.com", "EMail");
    emailElem.appendChild(doc.createTextNode(this.email));
    
    reqEnv.addHeader(new SOAPHeaderElement(emailElem));
---------------------------------- end
------------------------------------


Thanks

---
kazu




More information about the jdom-interest mailing list