java - jaxb, separate namespace for child element -


i trying create xml using jaxb below format, child element has separate name space.

 <soap:envelope xmlns:soap="http://demo.org/soap/envelope/"      xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema">       <soap:header>            <element1 xmlns="http://childnamespacehere">           <att1>test</att1>           <att2>test</att2>           </element1>             </soap:header>      <soap:body>          <element2 xmlns="http://childnamespacehere">             <att1>test</att1>             <att2>test</att2>         </element2 >     </soap:body> </soap:envelope> 

my class

  @xmlrootelement(name = "soap:envelope", namespace = "http://schemas.xmlsoap.org/soap/envelope/")   public class envelope           private element1 element1;         private element2  element2;      @xmlelementwrapper(name = "soap:header")     @xmlelement(name = "element1", namespace = "http://childelementnamespace/")     public void setelement1(element1 element){ }      @xmlelementwrapper(name = "soap:body")     @xmlelement(name = "element2" , namespace = "http://childelementnamespace/")     public void setelement2(element2 element){ } 

but getting xml generated below, child schema @ root level.

 <soap:envelope xsi:schemalocation="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://childelementnamespace/"  xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">         <soap:header>             <ns2:element1>                 <att1>value</att1>                 <att2>value</att2>             </ns2:element1>         </soap:header>         <soap:body>             <ns2:element2>                  <att1>value</att1>                 <att2>value</att2>             </ns2:element2>         </soap:body>     </soap:envelope> 

i have @xmlschema defined in package-info.java

 @xmlschema(namespace = "http://schemas.xmlsoap.org/soap/envelope/",     xmlns = { @javax.xml.bind.annotation.xmlns(prefix = "element1", namespaceuri = "http://childelementnamespace"),             @javax.xml.bind.annotation.xmlns(prefix = "element2", namespaceuri = "http://childelementnamespace") },             elementformdefault = xmlnsform.qualified)      package com.model;      import javax.xml.bind.annotation.xmlnsform;     import javax.xml.bind.annotation.xmlschema; 

when generate xml , name space child elements not getting generated , namespace root element.

in being generated has xmlns:ns2="http://childelementnamespace/" top, declaring namespace , used in fashion <ns2:element2> using ns2 here uses tha namspace declared previously.

so expecting , getting exact same declared in different places, jaxb method more correct not declaring same namespace more once.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -