[英]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.