1

I have got the following simple XML Schema...

<xs:complexType name="OrderReferenceType">
        <xs:sequence>
            <xs:element name="ReferenceID" type="xs:string"/>
        </xs:sequence>
        <xs:attribute name="Type">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="SalesOrder"/>
                    <xs:enumeration value="CustomerPO"/>
                    <xs:enumeration value="WorkOrder"/>
                    <xs:enumeration value="Misc"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:complexType>

And I'd like to hint to the XJC JAXB compiler so that it should generate the type safe enum class for "Type".

<jaxb:bindings schemaLocation="file:./WorkOrder.xsd">
<jaxb:bindings node="//xs:element[@name='ReferenceID']//xs:complexType//xs:attribute[@name='Type']//xs:simpleType">
    <jaxb:typesafeEnumClass name="TypeEnum" />
</jaxb:bindings>

But when i run the command

xjc -d src workOrder.xsd -b customizedBindings.xjb

i get the following error.

parsing a schema...
[ERROR] XPath evaluation of   "//xs:element[@name='ReferenceID']//xs:complexType//xs:attribute[@name='Type']//xs:simpleType" results in empty target node
line 69 of file:/C:/jaxB_workspace/jaxbExp/resources/mybindings.xjb

Failed to parse a schema.

Can someone help how to achieve this goal without modifying the original XSD?

user3555138
  • 11
  • 1
  • 2
  • I am not sure about the workings of the bindings file, but to run the xpath expression, somewhere you would have to declare the namespace of the `xs:` prefix (perhaps adding `xmlns:xs="http://www.w3.org/2001/XMLSchema"`) or use it without namespaces: `//*[local-name() = 'element'][@name='ReferenceID']//*[local-name()='complexType']//*[local-name() = 'attribute'][@name='Type']//*[local-name()='simpleType']` – helderdarocha Apr 21 '14 at 04:51

1 Answers1

1

Your XPath addresses the complex type somewhere inside the xs:element:

//xs:element[@name='ReferenceID']//xs:complexType//xs:attribute[@name='Type']//xs:simpleType
                                 ^^

But in your schema your element is the part of your complex type. So the XPath is not correct.

Please try:

//xs:complexType[@name='OrderReferenceType']/xs:attribute[@name='Type']/xs:simpleType
lexicore
  • 42,748
  • 17
  • 132
  • 221