繁体   English   中英

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

[英]Change the name of generated variable for referenced element in XSD using Jaxb and bindings

今天我有一个我无法解决的思维模式。 我将从解释和示例开始。

我有2个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>

第二个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引用ReportInfoWrapper(ReportInfo的根元素)。 我需要知道我将在JAXB Bindings文件中定义什么来更改ReportInfoRecordSet中此引用元素的生成名称。 这是它目前产生的:

public class ReportInfoRecordSetWrapper {

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

问题任何帮助或建议都将非常感激。 注意,我不能使ReportInfo的Root元素成为复杂的Type,因为它会破坏ReportInfo的当前绑定文件。 有没有办法用以下表示法定义变量的名称? 请注意,下面的示例由于某种原因不起作用(我相信它的节点定位问题“:

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

注意

一个简单的方法来看看我在这里尝试什么,我可以在正常的开发条款中解释。

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>

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

编辑2

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

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


<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM