使用 Jaxb 和绑定更改 XSD 中引用元素的生成变量的名称

Eon*_*Eon 4 java xsd reference jaxb xjb

今天我遇到了一个令人难以置信的问题,我无法解决。我将从解释和示例开始。

我有 2 个 XSD 文件。一个 XSD 文件引用另一个 XSD 文件的元素之一。

第一个 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>
Run Code Online (Sandbox Code Playgroud)

第二个 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>
Run Code Online (Sandbox Code Playgroud)

ReportInfoRecordSet 引用 ReportInfoWrapper(ReportInfo 的根元素)。我需要知道在 JAXB 绑定文件中定义什么来更改 ReportInfoRecordSet 中此引用元素的生成名称。这是它当前生成的:

public class ReportInfoRecordSetWrapper {

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

问题 任何帮助或建议将不胜感激。请注意,我无法将 ReportInfo 的根元素设置为复杂类型,因为它会破坏 ReportInfo 的当前绑定文件。有没有办法用下面的符号来定义变量的名称?请注意,下面的示例由于某种原因不起作用(我相信它的节点定位问题”:

      <jaxb:bindings node=".//xsd:element[@name='ReportInfoRecordSetWrapper']/xsd:complexType/xsd:sequence/xsd:node[@ref=ReportInfoWrapper"]">
         <jaxb:property name="records" />
      </jaxb:bindings>
Run Code Online (Sandbox Code Playgroud)

笔记

一种简单的方法来了解我在这里尝试的内容,我可以用正常的开发术语进行解释。

ReportInfo 是“类”

ReportInfoRecordSet 是 ReportInfo 类的数组。

编辑

<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>
Run Code Online (Sandbox Code Playgroud)

第 19 行抛出错误,指出 XPATH 错误:null。第 19 - 21 行是添加到我的代码中的新行。

编辑2

请记住孩子们,使用 XJC 需要您仔细检查向 XPATH 处理器提供的命名空间。我发现错误node="//*/xs:element[@ref='ReportInfoWrapper']"应该在 哪里node="//*/xsd:element[@ref='ReportInfoWrapper']"

kor*_*fey 5

此绑定必须有效(在本地检查):


<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>
Run Code Online (Sandbox Code Playgroud)