maven - Getting UnmarshalException while creating JAVA objects from xsd for specific xml -


i using xsd create java objects using maven-jaxb-plugin (com.sun.tools.xjc.maven2). while populating these java objects xml file getting following error.

javax.xml.bind.unmarshalexception: unexpected element "clients". expected elements "{http://www.company.com/enigma/utils/export}clients". 

xsd has following structure,

targetnamespace="http://www.company.com/enigma/utils/export">         <xs:element name="clients">           <xs:complextype>             <xs:sequence>               <xs:element name="client">                 <xs:annotation>                   <xs:documentation>client element represents client in jsp pages , name attribute should unique</xs:documentation>                 </xs:annotation>                 <xs:complextype>                   <xs:sequence>                     <xs:element name="column" maxoccurs="unbounded" minoccurs="1">                       <xs:complextype>                         <xs:simplecontent>                           <xs:extension base="xs:string">                             <xs:attribute type="xs:string" name="header" use="required"/>                             <xs:attribute type="xs:string" name="metaname" use="required"/>                             <xs:attribute type="xs:string" name="datatype" use="required"/>                           </xs:extension>                         </xs:simplecontent>                       </xs:complextype>                     </xs:element>                   </xs:sequence>                                     <xs:attribute type="xs:string" name="name" use="required"/>                   <xs:attribute type="xs:string" name="useresource" use="required"/>                   <xs:attribute type="xs:string" name="resourcefile" use="required"/>                 </xs:complextype>                 <xs:unique name="uniqueclientname">                     <xs:selector xpath="client"></xs:selector>                     <xs:field xpath="@name"></xs:field>                 </xs:unique>               </xs:element>             </xs:sequence>           </xs:complextype>         </xs:element> </xs:schema> 

and xml below,

<?xml version="1.0" encoding="utf-8"?> <clients xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">     <client name="clientdetails" useresource="true">             <column header="clientdetails.clientname" metaname="name" datatype="string"/>             <column header="clientdetails.physicaladdress" metaname="phyaddress" datatype="string"/>             <column header="clientdetails.city" metaname="city" datatype="string"/>             <column header="clientdetails.state" metaname="state" datatype="string"/>     </client> </clients> 

all jaxb classes generated using maven , in enigma/utils/export folder. don't able solve issue. please me on this.

please try below code giving package of generated classes. per xml should com.enigma.utils.export

jaxbcontext jaxbcontext = jaxbcontext.newinstance("com.enigma.utils.export"); unmarshaller  unmarshaller = jaxbcontext.createunmarshaller(); 

this may solve problem.


Comments