Search code examples
xmlmavenjaxbxsdhyperjaxb

XPath evaluation of "xs:complexType[@name='Any']" results in empty target node


I am trying to get hyperjaxb to process a real schema. I downloaded and unzipped the hyperjaxb maven project from this link and then navigated to the root directory using cmd.exe and tested it with the sample data by running mvn clean install to make sure that it works with the example schema. I then replaced the schema.xsd, po.xml, and bindings.xjb files with a stripped down version of actual shematics so that I can prepare to run a real app through the above-linked hyperjaxb project. I then ran mvn clean install again. However, I am getting the following error message:

[ERROR] Error while parsing schema(s).Location 
[ file:/C:/path/to/src/main/resources/bindings.xjb{25,53}].
com.sun.istack.SAXParseException2; systemId: 
file:/C:/path/to/src/main/resources/bindings.xjb; lineNumber: 25; columnNumber: 53; 
XPath evaluation of "xs:complexType[@name='Any']" results in empty target node  

from the replacement bindings.xjb file that you can read at this link. using the schema.xsd file at this link, and the po.xml that you can read at this link.

The relevant section of bindings.xjb is:

<jaxb:bindings node="xs:complexType[@name='Any']">
    <hj:entity>
        <orm:table name="any"/>
    </hj:entity>
</jaxb:bindings>

The definition of the ANY complexType in schema.xsd is:

<xs:complexType name="ANY"><!-- abstract="true">-->
  <xs:annotation>
    <xs:documentation>
        Some documentation.
    </xs:documentation>
  </xs:annotation>
  <xs:attribute name="nullFlavor" type="NullFlavor" use="optional">
    <xs:annotation>
      <xs:documentation>
           Some other documentation.
        </xs:documentation>
    </xs:annotation>
  </xs:attribute>
</xs:complexType>  

Note that the complete code is in the links above. How can I resolve this error?


Solution

  • You should use below configuration..

    <jaxb:bindings node="//xs:complexType[@name='ANY']">
        <hj:entity>
            <orm:table name="any"/>
        </hj:entity>
    </jaxb:bindings>
    

    An example could you find in this my answer of another topic. https://stackoverflow.com/a/24953369/3364187


    I tried your project, this configuration works fine. Let me know if works in your environment.

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <jaxb:bindings
        version="2.1"
        xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations"
        xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
        jaxb:extensionBindingPrefixes="hj orm">
    
        <jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
            <jaxb:globalBindings generateIsSetMethod="true"/>
            <jaxb:schemaBindings>
                <jaxb:package name="org.jvnet.hyperjaxb3.ejb.tests.pocustomized"/>
            </jaxb:schemaBindings>
            <jaxb:bindings node="//xs:complexType[@name='InfrastructureRoot.typeId']">
                <hj:entity>
                    <orm:table name="typeId"/>
                </hj:entity>
            </jaxb:bindings>
            <jaxb:bindings node="//xs:complexType[@name='II']">
                <hj:entity>
                    <orm:table name="II"/>
                </hj:entity>
            </jaxb:bindings>
            <jaxb:bindings node="//xs:complexType[@name='ANY']">
                <hj:entity>
                    <orm:table name="any"/>
                </hj:entity>
            </jaxb:bindings>
        </jaxb:bindings>
    
    
    </jaxb:bindings>
    

    In brief for each node was missing //

    Selects nodes in the document from the current node that match the selection no matter where they are

    and the complex type isn't "Any" but "ANY", then, the correct node is @name='ANY'