xsd 自定義list 實現
最近需要跟第三方連調介面,在針對返回xml解析的時候,生成xsd響應報文,返回一個list集合
以下是參考資料和 實際解決方案例:我的xml響應報文是以下格式
<?xml version="1.0" encoding = "GBK"?>
<root>
<Head>
<OpName></OpName><!--交易型別 4位-->
<OpRetCode></OpRetCode><!--返回碼 2位 00:成功 01:失敗-->
<OpRetMsg></OpRetMsg><!--返回碼對應文字資訊 80位-->
</Head>
<Param>
<RecordSet><!--多條RecordSet-->
<Cust_Acct></Cust_Acct><!--交易賬號 32位-->
<Acct_Name></Acct_Name><!--交易賬號名稱 60位-->
<Name></Name><!--對方戶名 60位-->
<Account></Account><!--對方賬號 32位-->
<Bank></Bank><!--對方開戶行全稱 60位-->
<Bank_Id></Bank_Id><!--對方開戶行行號 20位-->
<Amount></Amount><!--發生金額 13位 無小數點單位為分-->
<Balance></Balance><!--轉賬後餘額 13位 無小數點單位為分-->
<Flag></Flag><!--轉出轉入標誌 0-借 1-貸1位-->
<Bank_Serial></Bank_Serial><!--銀行流水號 12位-->
<EnterpriseID></EnterpriseID><!--企業流水號32位-->
<Trans_Date></Trans_Date><!--轉賬日期 格式yyyymmdd 8位-->
<Trans_Time></Trans_Time><!--轉賬時間 格式hhmmss 6位-->
<Tx_Flag></Tx_Flag><!--交易型別 20位-->
<Vchr_Type></Vchr_Type><!--憑證名稱 40位-->
<Vchr_No></Vchr_No><!--憑證號碼 32位-->
<Usage></Usage><!--用途 40位-->
<Remark></Remark><!--摘要 40位-->
<Chnl_Code></Chnl_Code><!--交易渠道 40位-->
<Reserved1></Reserved1><!--備用欄位1 40位-->
<Reserved2></Reserved2><!--備用欄位2 40位-->
<Reserved3></Reserved3><!--備用欄位3 40位-->
<Reserved4></Reserved4><!--備用欄位4 40位-->
</RecordSet>
</Param>
</root>
RecordSet存在多條的情況
1、參考XML Schema list案例
因為simpleType的list都是簡單型別,無法支援複雜的自定義型別,遂考慮用group組概念。
2、XML Schema group 案例
但是使用group 之後,發現生成的javabean還是 Object,而不是list或者Array。參考各方面資料,遂發現一個屬性:maxOccurs="unbounded"
3、maxOccurs="unbounded" 的詳細解釋
下面是我的xsd格式和關於複雜自定義list的使用案例
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="RepBaseRoot.xsd"/>
<xs:group name="rs">
<xs:sequence>
<xs:element type="xs:string" name="Cust_Acct">
<xs:annotation>
<xs:documentation>多條RecordSet多條RecordSet</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Acct_Name">
<xs:annotation>
<xs:documentation>交易賬號 32位交易賬號 32位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Name">
<xs:annotation>
<xs:documentation>交易賬號名稱 60位交易賬號名稱 60位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Account">
<xs:annotation>
<xs:documentation>對方戶名 60位對方戶名 60位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Bank">
<xs:annotation>
<xs:documentation>對方賬號 32位對方賬號 32位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Bank_Id">
<xs:annotation>
<xs:documentation>對方開戶行全稱 60位對方開戶行全稱 60位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Amount">
<xs:annotation>
<xs:documentation>對方開戶行行號 20位對方開戶行行號 20位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Balance">
<xs:annotation>
<xs:documentation>發生金額 13位 無小數點單位為分發生金額 13位 無小數點單位為分</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Flag">
<xs:annotation>
<xs:documentation>轉賬後餘額 13位 無小數點單位為分轉賬後餘額 13位 無小數點單位為分</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Bank_Serial">
<xs:annotation>
<xs:documentation>轉出轉入標誌 0-借 1-貸1位轉出轉入標誌 0-借 1-貸1位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="EnterpriseID">
<xs:annotation>
<xs:documentation>銀行流水號 12位銀行流水號 12位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Trans_Date">
<xs:annotation>
<xs:documentation>企業流水號32位企業流水號32位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Trans_Time">
<xs:annotation>
<xs:documentation>轉賬日期 格式yyyymmdd 8位轉賬日期 格式yyyymmdd 8位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Tx_Flag">
<xs:annotation>
<xs:documentation>轉賬時間 格式hhmmss 6位轉賬時間 格式hhmmss 6位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Vchr_Type">
<xs:annotation>
<xs:documentation>交易型別 20位交易型別 20位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Vchr_No">
<xs:annotation>
<xs:documentation>憑證名稱 40位憑證名稱 40位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Usage">
<xs:annotation>
<xs:documentation>憑證號碼 32位憑證號碼 32位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Remark">
<xs:annotation>
<xs:documentation>用途 40位用途 40位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Chnl_Code">
<xs:annotation>
<xs:documentation>摘要 40位摘要 40位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Reserved1">
<xs:annotation>
<xs:documentation>交易渠道 40位交易渠道 40位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Reserved2">
<xs:annotation>
<xs:documentation>備用欄位1 40位備用欄位1 40位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Reserved3">
<xs:annotation>
<xs:documentation>備用欄位2 40位備用欄位2 40位</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element type="xs:string" name="Reserved4">
<xs:annotation>
<xs:documentation>備用欄位3 40位備用欄位3 40位</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:group>
<xs:element name="RepQueryAcctDtl">
<xs:complexType>
<xs:complexContent>
<xs:extension base="RepBaseRoot">
<xs:sequence>
<xs:element name="Param">
<xs:complexType>
<xs:sequence>
<xs:element name="RecordSet" maxOccurs="unbounded">
<xs:complexType>
<xs:group ref="rs"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>
上述程式碼,我定義了一個group, 並在集合元素裡面引用了group, 但是對於多個RecordSet, 通過maxOccurs="unbounded" 來實現將其變成List
最後生成的JavaBean: recordSet這個屬性就是集合了
相關文章
- XSD中自定義型別的三種方式型別
- 自定義View:自定義屬性(自定義按鈕實現)View
- 自定義View:畫布實現自定義View(折線圖的實現)View
- Net 實現自定義Aop
- EventSource的自定義實現
- 微信分享自定義實現
- mybatis自定義List集合解析器MyBatis
- Android Studio通過style和layer-list實現自定義進度條Android
- 自定義SpringMVC部分實現SpringMVC
- Android自定義拍照實現Android
- Flutter自定義Banner的實現Flutter
- Flutter自定義View的實現FlutterView
- 自定義實現Complex類
- 自定義view實現半圓環View
- Android 實現自定義圓環Android
- 在 Admin 中自定義 list_filterFilter
- 如何定義Xsd檔案
- Flutter實現自定義篩選框Flutter
- Qt實現自定義控制元件QT控制元件
- CefSharp自定義快取實現快取
- avalonia實現自定義小彈窗
- 自定義簡單彈幕實現
- 實現自定義LookupComboBox薦
- Laravel 實現自定義生成檔案命令Laravel
- .Net Core中自定義認證實現
- JavaScript實現自定義的生命週期JavaScript
- vue-自定義指令-實現提示功能Vue
- 淺談如何實現自定義的 iterator
- 實現MyBatisPlus自定義sql注入器MyBatisSQL
- 自定義Drawable:實現文字生成圖片
- canvas之自定義頭像功能實現Canvas
- 自定義View:側滑選單實現View
- Jquery實現自定義訊息彈窗jQuery
- 自定義RecyclerView實現側滑刪除View
- jQuery如何實現新增自定義函式jQuery函式
- Android程式碼實現自定義ButtonAndroid
- 自定義collocationViewLayout實現多區瀑布流View
- DataTables自定義分頁條數實現