JAXB xjc expected element of type …

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
Software & Development

Xalan Xsl and Lookup tables

If you don’t know what is a lookup table in context of Xsl transformation you might like these short example articles here or here

The common way to use lookup tables in Xsl transformations is to use select=”document(”)/*/data/” syntax. If there is no path provided and the parameter of document() function is string, the function returns the reference to the stylesheet itself. However, this is not true for all Xsl transformation libraries.

In case you use Xalan and the document is loaded from database, you might get into trouble – the function will not find anything. The workaround is to load a different Xml document by calling document(‘data.xml’). Yes, there’s a but too. Xalan will look for the document in the java application startup path, not in the same location as the Xsl stylesheet, nor in the path of Xml document being transformed (it is in database, you remember, right?). In case your application is a web application running in Apache, the startup path is apache/bin