JAXB generating wrong Namespace -


i have xsd (lets name afb) imports xsd (lets name kts). , refer element of kts.xsd in afb.xsd along correct namespaces.

but when generate classes using jaxb, namespace refered element wrong.

i mean, referred element should have kts namespace having afb namespace.

because of validating xml against xsd failing not able bind xml data java models.

ex: afb.xsd :

<xs:import namespace="http://www.boschkts.com" schemalocation="kts.xsd"/> <xs:element name="vehicle">  <xs:complextype>         <xs:sequence>           <xs:element ref="vtype"/>           <xs:element name="results" type="kts:results" >         </xs:sequence>     </xs:complextype> </xs:element> 

kts:xsd :

<xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns="http://www.boschkts.com"  targetnamespace="http://www.boschkts.com" elementformdefault="qualified">  <xs:complextype name="results">     <xs:sequence>         <xs:element name="summary" type="summary" minoccurs="0" />     </xs:sequence> </xs:complextype> 

vehicle.java :

public class vehicle {      @xmlelement(namespace = "http://www.boschafb.com", required = true)     protected string vtype;     @xmlelement(name = "results", namespace = "http://www.boschafb.com", required = true)     protected results results;  } 

if observe vehicle.java, namespace of results property should have been "http://www.boschkts.com" instead of "http://www.boschafb.com"

if change namespace manually binding data xml java models works. still validating against xsd fails error :

caused by: org.xml.sax.saxparseexception: cvc-complex-type.2.4.a: invalid content found starting element 'kts:results'. 1 of '{"http://www.boschafb.com":results}' expected.

can point might missing in xsd? or way jaxb generates , have modify classes manually?

regards,

satya

i'm assuing abf.xsd starts with

<xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns="http://www.boschafb.com"            targetnamespace="http://www.boschafb.com" elementformdefault="qualified"> 

with elementformdefault set qualified, element declarations, nested ones, belong specified target namespace. note applies elements, referenced type not affect namespace of element referencing it.

a solution define element instead of type in 'kts.xsd' , referencing element in first schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns="http://www.boschkts.com"             targetnamespace="http://www.boschkts.com" elementformdefault="qualified">     <xs:element name="results">         <xs:complextype>             <xs:sequence>                 <xs:element name="summary" type="summary" minoccurs="0" />             </xs:sequence>         </xs:complextype>     </xs:element> </xs:schema>  <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns="http://www.boschafb.com"            targetnamespace="http://www.boschafb.com" elementformdefault="qualified"            xmlns:kts="http://www.boschkts.com">      <xs:import namespace="http://www.boschkts.com" schemalocation="kts.xsd"/>      <xs:element name="vehicle">         <xs:complextype>             <xs:sequence>                 <xs:element ref="vtype"/>                 <xs:element ref="kts:result"/>             </xs:sequence>         </xs:complextype>     </xs:element> </xs:schema> 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -