簡體   English   中英

使用Spring Validator進行自定義XSD模式驗證

[英]custom xsd schema validation using spring validator

這是我在該論壇上的第一篇文章。

我有一個表示pnr(航班)預訂列表的xml。 在此內部,有單個pnrs的列表。 現在,如果一個pnr有一個無效字段,則在再次驗證xml模式時,我們將出現肥皂故障,並且驗證似乎在第一個錯誤點停止了。

因此,從本質上講,如果一次飛行中有100個pnr,如果一個pnr包含無效字段,則由於該一個無效pnr,整個響應都會丟失。 要求是拒絕有錯誤的pnr,並與其余有效pnr一起發送響應。

如何通過Spring XSD驗證通過配置或以編程方式實現此目標。

    <complexType name="DutBookings">
    <sequence>
        <element name="RecCount" type="long" minOccurs="1" maxOccurs="1"/>
        <element name="DutBooking" type="tns:DutBooking" minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
</complexType>  
<!--  -->   
<complexType name="DutBooking">
    <annotation>
        <documentation>
            This holds the booking record. 
            The frequent flyer details and airline customer value held at this level represents
            the highest tier / value for all passengers associated with the booking.
        </documentation>
    </annotation>
    <sequence>
        <element name="BookingReference" type="tns:FlightBookingReference" minOccurs="0"/>
        <element name="BookingDate" type="dateTime" minOccurs="0"/>
        <element name="BookingStatus" type="tns:BookingStatus" minOccurs="0"/>
        <element name="BookingType" type="tns:BookingType" minOccurs="0"/>
        <element name="CreatingBookingOffice" type="tns:OfficeID" minOccurs="0"/>
        <element name="POSCity" type="tns:CityCode" minOccurs="0"/>
        <element name="POSCountry" type="tns:ISO_CountryCode" minOccurs="0"/>
        <element name="NameCount" type="tns:Count" minOccurs="0">
            <annotation>
                <documentation>Number of real names on booking, includes infants</documentation>
            </annotation>
        </element>
        <element name="ReservationCount" type="tns:Count" minOccurs="0">
            <annotation>
                <documentation>Count of passengers on booking, excludes infants</documentation>
            </annotation>
        </element>
        <element name="MaxAirlineCustomerValue" type="int" minOccurs="0"/>
        <element name="CabinCode" type="tns:CabinCode" minOccurs="0"/>
        <element name="BookingClass" type="tns:SellingClass" minOccurs="0"/>
        <element name="SplitCount" type="tns:Count" minOccurs="0">
                <annotation>
                    <documentation>Number of names split from the booking</documentation>
                </annotation>
        </element>
        <element name="SplitParentBookingReference" type="tns:FlightBookingReference" minOccurs="0"/>
        <element name="StaffNumber" type="tns:StaffNumber" minOccurs="0"/>
        <element name="StaffJoiningDate" type="date" minOccurs="0"/>
        <element name="StaffTravelPriorityCode" type="tns:StaffTravelPriorityCode" minOccurs="0"/>
        <element name="BookingPassenger" type="tns:BookingPassenger" minOccurs="0" maxOccurs="unbounded"/>
        <element name="SuitabilityKeyword" type="tns:SuitabilityKeyword" minOccurs="0" maxOccurs="unbounded"/>
        <element name="DutServiceLine" type="tns:DutServiceLine" minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
</complexType>

因此,您可以看到存在dutbookings元素,其中包含dutbooking列表。 如果一次預訂中有驗證錯誤,我想繼續其余的。

提前致謝。

如果您檢查整個文檔,則所有文檔都將根據架構進行檢查。

一種更具編程性的方法是分別驗證內部預訂清單。 提取預訂元素列表,然后將有效元素重新打包到列表中,而忽略(並記錄?)未通過驗證的元素。

您似乎沒有選擇將模式重新定義為“允許可選”的選項,或者導致pnr預訂失敗的任何選項。 然后驗證就會通過,但這並不是您想要的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM