4

Today I have a mindboggler I just cannot solve. I will start with an Explanation and Example.

I have 2 XSD Files. The one XSD File References one of the other's elements.

First XSD- ReportInfo.xsd:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xs:schema id="ReportInfoWrapper" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="ReportInfoWrapper" >
    <xs:complexType>
      <xs:sequence>
          ...
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Second XSD- ReportInfoRecordSet.xsd:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xs:schema id="ReportInfoRecordSetWrapper" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:include schemaLocation="./ReportInfo.xsd" />
  <xs:element name="ReportInfoRecordSetWrapper">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="ReportInfoWrapper" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

ReportInfoRecordSet references ReportInfoWrapper (The root element of ReportInfo). I need to know what I would define in the JAXB Bindings file to change the generated name for this referenced element in ReportInfoRecordSet. This is what it currently generates:

public class ReportInfoRecordSetWrapper {

@XmlElement(name = "ReportInfoWrapper", required = true)
protected List<ReportInfoWrapper> reportInfoWrappers; //I need to change the name here in the bindings file.

The Question Any help or advice will be greatly appreciative. Note, I cannot make ReportInfo's Root element a complex Type, as it would break the current bindings file for ReportInfo. Is there any way to define the variable's name in the following notation? Note this example below does not work for some reason (I believe its node targeting issues":

      <jaxb:bindings node=".//xsd:element[@name='ReportInfoRecordSetWrapper']/xsd:complexType/xsd:sequence/xsd:node[@ref=ReportInfoWrapper"]">
         <jaxb:property name="records" />
      </jaxb:bindings>

Note

An easy way to see what I am trying here, I could explain in normal developing Terms.

ReportInfo is the "class"

ReportInfoRecordSet is an Array of ReportInfo classes.

EDIT

<jaxb:bindings
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
    xmlns:annox="http://annox.dev.java.net"
    jaxb:extensionBindingPrefixes="xjc inheritance annox"
    version="2.1">
    <jaxb:globalBindings localScoping="toplevel">
        <xjc:simple />
        <xjc:javaType adapter="aem.adservices.google.dfa.utils.DateAdapter" name="java.util.Calendar" xmlType="xs:dateTime" />
    </jaxb:globalBindings>
    <jaxb:bindings schemaLocation="../xsd/ReportInfoRecordSet.xsd" >
      <jaxb:bindings node=".//xsd:element[@name='ReportInfoRecordSetWrapper']/xsd:complexType">
         <annox:annotate>
           <annox:annotate annox:class="aem.utilities.boomi.BoomiObject" label="ReportInfoRecordSet" description="ReportInfoRecordSet" OperationTypes="UPSERT"  />
         </annox:annotate>
      </jaxb:bindings>
       <jaxb:bindings node="//*/xs:element[@ref='ReportInfoWrapper']">
           <jaxb:property name="records"/>
       </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>

The Error is thrown at line 19 saying XPATH error: null. Lines 19 - 21 are new lines added to my code.

EDIT 2

Remember kids, working with XJC requires you to double check which namespaces you provide to the XPATH Processor. I found the mistake where node="//*/xs:element[@ref='ReportInfoWrapper']" should be node="//*/xsd:element[@ref='ReportInfoWrapper']"

Eon
  • 3,833
  • 10
  • 46
  • 75
  • another note, sure, I can go and manually change the name, but I have an estimated of 89 xsd files which will end like this, and it would be inefficient for me to go and find referenced variables' names to change. – Eon Dec 04 '12 at 11:38

1 Answers1

5

This binding must work (checked locally):


<jxb:bindings version="1.0" 
  xmlns:jxb="http://java.sun.com/xml/ns/jaxb" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
  jxb:extensionBindingPrefixes="xjc">
    <jxb:bindings schemaLocation="ReportInfoRecordSet.xsd" node="/xs:schema">
       <jxb:bindings node="//*/xs:element[@ref='ReportInfoWrapper']">
            <jxb:property name="records"/>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>
korifey
  • 3,379
  • 17
  • 17
  • This is odd. What I get is: [xjc] [ERROR] XPath error: null [xjc] line 19 of file:/C:/eclipse/Workspace/XXXXXXXXX/XXXXXXXX/xjb/ReportInfoRecordSet.xjb – Eon Dec 04 '12 at 12:00
  • I mean, the XPath checks out, yet still throws an error where it doesn't seem like it is supposed to. Any advice? – Eon Dec 04 '12 at 12:05
  • I will add my entire XJB to the question for you to have a look :) – Eon Dec 04 '12 at 12:07
  • I'm an Idiot. Forgot to double check if the XPATH Processor runs through the correct namespaces. You have defined your namespace as xs, and I have defined mine as xsd. – Eon Dec 04 '12 at 12:17
  • Was it helpful, eventually? – korifey Dec 04 '12 at 12:42