1

I'm generating the Java classes corresponding to the XML-Schema at https://cwe.mitre.org/data/xsd/cwe_schema_v6.10.xsd but most of the generated classes are undesired since they belong to the imported namespace:

<xs:import namespace="http://www.w3.org/1999/xhtml"
schemaLocation="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd"/>

Indeed, if I simply comment out this import statement then the generated classes go from 149 (mostly HTML elements) to just 59 (all belonging to the input schema domain).

My question is if/how it is possible to skip/ignore the generation of Java classes for certain XML elements and in this case the elements defined in an imported namespace, defining some custom rules in a .xjb file.

The solution available at https://stackoverflow.com/a/20907846/8737144 didn't work in my case, returning the following error

com.sun.istack.SAXParseException2: compiler was unable to honor this class customization. It is attached to a wrong place, or its inconsistent with other bindings.

It is possible to test the generation using the following command:

xjc http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd -b cwe-bindings.xjb

<!-- cwe-bindings.xjb -->
<jxb:bindings version="3.0"
              xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
              xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <jxb:bindings schemaLocation="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd" node="//xsd:schema">
        <jxb:schemaBindings>
            <jxb:package name="com.example.cwe"/>
        </jxb:schemaBindings>

        <!-- rename the 'lang' attribute on line 302 to 'langAttribute' -->
        <jxb:bindings node="//xsd:attributeGroup[@name='i18n']/xsd:attribute[@name='lang']">
            <jxb:property name="langAttribute"/>
       </jxb:bindings>
       
        <!-- rename the 'lang' attribute on line 1166 to 'langAttribute' -->
       <jxb:bindings node="//xsd:element[@name='bdo']/xsd:complexType/xsd:complexContent/xsd:extension/xsd:attribute[@name='lang']">
            <jxb:property name="langAttribute"/>
       </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>
1Z10
  • 2,801
  • 7
  • 33
  • 82

0 Answers0