users@jaxb.java.net

Customization and XPath Expressions

From: Slein, Judith A <JSlein_at_crt.xerox.com>
Date: Thu, 18 Sep 2003 13:19:57 -0400

I've been trying to get customization to work when generating java classes
for an XML Schema. But everyplace I use an XPath expression that includes a
predicate, I get an error like:

 

[ERROR] XPath evaluation of "//xs:attribute[@name='Class']" results in empty
target node

 

This XPath expression is exactly like a sample that does work, so I need
help understanding what I'm doing wrong.

 

Here is the binding.xjb file:

 

<jxb:bindings version="1.0"

               xmlns:jxb="http://java.sun.com/xml/ns/jaxb"

               xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <jxb:bindings schemaLocation="JDF.xsd" node="/xs:schema">

  

            <jxb:globalBindings collectionType="java.util.Vector"

                        fixedAttributeAsConstantProperty="true"

                        underscoreBinding="asCharInWord"

                        typesafeEnumBase="xs:NMTOKEN"/>

 

    <jxb:schemaBindings>

      <jxb:package name="com.xerox.SIToolkit.XMLDB.JDFSchema"/>

 

      <jxb:nameXmlTransform>

        <jxb:elementName prefix="e"/>

        <jxb:anonymousTypeName prefix="t"/>

      </jxb:nameXmlTransform>

    </jxb:schemaBindings>

 

 

      <!-- resolve name collision with java keyword class -->

<!-- This is exactly like the sample, except that in the sample it is an

     element that is being fixed. But here it produces an Error: XPath
evaluation

             results in empty target node.

             In fact, everywhere I put a predicate in an XPath expression, I
get

             that error.

             But if I take off the predicate, I get "too many nodes in
target" Error.

-->

      <jxb:bindings node="//xs:attribute[@name='Class']">

        <jxb:property name="class_"/>

      </jxb:bindings>

 

      <jxb:bindings node="//xs:group[@name='PreflightGroup_r']">

                        <jxb:bindings
node="//xs:element[@name='PreflightDetail']">

                                    <jxb:class name="trPreflightDetail"/>

                        </jxb:bindings>

              </jxb:bindings>

 

              <jxb:bindings node="//xs:group[@name='PreflightGroup_u']">

                        <jxb:bindings
node="//xs:element[@name='PreflightDetail']">

                                    <jxb:class name="tuPreflightDetail"/>

                        </jxb:bindings>

              </jxb:bindings>

 

  </jxb:bindings>

 

</jxb:bindings>

 

Here is a fragment of the XML Schema, which shows that there is an attribute
with the name "Class". In fact, there are several in the schema.

 

   <xs:complexType name="NotificationAudit">

      <xs:complexContent>

         <xs:extension base="jdf:AuditElement">

            <xs:sequence minOccurs="0" maxOccurs="unbounded">

               <xs:group ref="jdf:GenericElements" minOccurs="0"/>

               <xs:element name="CostCenter" type="jdf:CostCenter_re"
minOccurs="0"/>

               <xs:element name="Employee" type="jdf:Employee_re"
minOccurs="0"/>

               <xs:element name="EmployeeRef" type="jdf:ResourceRef"
minOccurs="0"/>

               <xs:element ref="jdf:NotificationDetails" minOccurs="0"/>

               <xs:element name="Part" type="jdf:Part" minOccurs="0"/>

            </xs:sequence>

            <xs:attribute name="Class" type="jdf:eNotificationClass_"
use="required"/>

            <xs:attribute name="Type" type="xs:NMTOKEN" use="optional"/>

         </xs:extension>

      </xs:complexContent>

   </xs:complexType>

 

The command line I am using to run is:

 

C:\JAXB\JDF>xjc -d Generated -p com.xerox.SIToolkit.XMLDB.JDFSchema -b
binding.xjb -extension JDF.xsd

 

Thanks.

 

Judith A. Slein

Xerox Corporation

1(585)422-5169