JAXB xjc expected element of type …

lacike/ November 21, 2012/ Hints/ 0 comments

If you have trouble loading Xml using classes generated by xjc tool (included in JAXB distribution), be carefull and do not define XSD main element like this:

<!-- MAIN element -->
<xs:element name="main" type="Main">
<xs:complexType name="Main">
...

The problem here is that the main element and main element type names are identical (except the first letter that is uppercased). Xjc creates a class for for both root Xml element and all complex types defined in Xsd. In this case a java class that derives from class for xsd complexType would be empty. If you still insist on having java class for xml root element then declare it as a extension without any additions.

Solutions (2):

  • declare xml root element as complexType extension (complexContent/complextType/extension) of the xsd complexType
  • do not define type for root element and define the structure directly in xs:element
pošli na vybrali.sme.sk

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
*
*

Blue Captcha Image
Refresh

*