温馨提示:本文翻译自stackoverflow.com,查看原文请点击:xml - ERROR: Element 'Return': No matching global declaration available for the validation root
xml xsd

xml - 错误:元素“返回”:没有匹配的全局声明可用于验证根

发布于 2020-04-15 23:34:02

我正在尝试使用xsd文件验证xml文件,以提交加拿大税务局的T2202 TAX SLIP

以下是我的xml文件,可以对其稍作更改以通过xsd模式文件进行验证。

<?xml version="1.0" encoding="UTF-8"?>

<Return>
    <T2202>
        <T2202Slip>
            <SlipReportTypeCode>O</SlipReportTypeCode>
            <FilerAccountNumber>000000000RZ0000</FilerAccountNumber>
            <PostSecondaryEducationalSchoolProgramName>Webdevelopment</PostSecondaryEducationalSchoolProgramName>
            <PostSecondaryEducationalSchoolTypeCode>1</PostSecondaryEducationalSchoolTypeCode>
            <FlyingSchoolClubCourseTypeCode>1</FlyingSchoolClubCourseTypeCode>
            <StudentName>
                <FamilyName>Jacob</FamilyName>
                <GivenName>peter</GivenName>
                <NameInitialText>k</NameInitialText>
            </StudentName>
            <SocialInsuranceNumber>000000000</SocialInsuranceNumber>
            <StudentNumber>501058988</StudentNumber>
            <StudentAddress>
                <AddressLine1Text>202-2526 LAKEVIEW</AddressLine1Text>
                <AddressLine2Text>CRES</AddressLine2Text>
                <CityName>ABBOTSFORD</CityName>
                <ProvinceStateCode>BC</ProvinceStateCode>
                <CountryCode>CAN</CountryCode>
                <PostalZipCode>V2W3A9</PostalZipCode>
            </StudentAddress>
            <SchoolSession>
                <StartYearMonth>1901</StartYearMonth>
                <EndYearMonth>1909</EndYearMonth>
                <EligibleTuitionFeeAmount>153.64</EligibleTuitionFeeAmount>
                <PartTimeStudentMonthCount>9</PartTimeStudentMonthCount>
                <FullTimeStudentMonthCount>0</FullTimeStudentMonthCount>
            </SchoolSession>
            <TotalEligibleTuitionFeeAmount>0</TotalEligibleTuitionFeeAmount>
            <TotalPartTimeStudentMonthCount>0</TotalPartTimeStudentMonthCount>
            <TotalFullTimeStudentMonthCount>0</TotalFullTimeStudentMonthCount>
        </T2202Slip>
        <T2202Summary>
            <FilerAccountNumber>000000000RZ0000</FilerAccountNumber>
            <SummaryReportTypeCode>O</SummaryReportTypeCode>
            <TaxationYear>2019</TaxationYear>
            <TotalSlipCount>1</TotalSlipCount>
            <PostSecondaryEducationalInstitutionName>
                <NameLine1Text>CAREER COLLEGE</NameLine1Text>
            </PostSecondaryEducationalInstitutionName>
            <PostSecondaryEducationalInstitutionMailingAddress>
                <CityName>ABBOTSFORD</CityName>
                <ProvinceStateCode>BC</ProvinceStateCode>
                <CountryCode>CAN</CountryCode>
                <PostalZipCode>V2W3A9</PostalZipCode>
            </PostSecondaryEducationalInstitutionMailingAddress>
            <ContactInformation>
                <ContactName>JOHN</ContactName>
                <ContactAreaCode>604</ContactAreaCode>
                <ContactPhoneNumber>720-4037</ContactPhoneNumber>
                <ContactExtensionNumber>6789</ContactExtensionNumber>
            </ContactInformation>
            <TotalEligibleTuitionFeeAmount>153.64</TotalEligibleTuitionFeeAmount>
        </T2202Summary>
    </T2202>
</Return>

请在我的xsd模式文件下面找到该文件,该文件来自政府网站。

<?xml version="1.0" encoding="ISO-8859-1"?>

<!--
Description T2202 Return Complex and Element Types
Last updated    May 2019
Version#:   1.19 (version #.yy)
-->

<xsd:schema xmlns:sdt="http://www.cra-arc.gc.ca/xmlns/sdt/2-2-0" 
    xmlns:ccms="http://www.cra-arc.gc.ca/xmlns/ccms/1-0-0" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:import namespace="http://www.cra-arc.gc.ca/xmlns/sdt/2-2-0" schemaLocation="standarddatatypes.xsd"/>
    <xsd:import namespace="http://www.cra-arc.gc.ca/xmlns/ccms/1-0-0" schemaLocation="cracommonstructures.xsd"/>
    <xsd:include schemaLocation="lemmcommontypes.xsd"/>

    <xsd:complexType name="T2202SlipType">
        <xsd:sequence>
            <xsd:element ref="SlipReportTypeCode"/>
            <xsd:element name="FilerAccountNumber" type="BNRZType"/>
            <xsd:element name="PostSecondaryEducationalSchoolProgramName" type="Length1to30TextType"/>

            <!-- School type code:
                1. University
                2. College
                3. Other education institution providing courses at a post-secondary school level
                4. Certified by the Minister of Employment and Social Development Canada
                5. Flying school or club
            -->
            <xsd:element name="PostSecondaryEducationalSchoolTypeCode" type="OneToFiveCodeType"/>

            <!-- Flying school or club course type code. Must have a value if School type code is 5,
                 should be blank if school type code is 1-4. Valid values:
                1. Private pilots license
                2. Commercial pilots licence
                3. Civil flying instructor rating
                4. Helicopter category rating
                5. Instrument rating
                6. Other
            -->
            <xsd:element name="FlyingSchoolClubCourseTypeCode" type="OneToSixCodeType" minOccurs="0"/>
            <xsd:element name="StudentName" type="IndividualNameType"/>
            <xsd:element name="SocialInsuranceNumber" type="ccms:SINType"/>
            <xsd:element name="StudentNumber" type="Length1to20TextType" minOccurs="0"/>
            <xsd:element name="StudentAddress" type="RequiredLine1AddressType"/>
            <xsd:element name="SchoolSession" type="SchoolSessionType" minOccurs="1" maxOccurs="4"/>
            <xsd:element name="TotalEligibleTuitionFeeAmount" type="Decimal13AmountType" minOccurs="0"/>
            <xsd:element name="TotalPartTimeStudentMonthCount" type="ZeroToTwelveCountType"/>
            <xsd:element name="TotalFullTimeStudentMonthCount" type="ZeroToTwelveCountType"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="SchoolSessionType">
        <xsd:all>
            <xsd:element name="StartYearMonth" type="YYMMType"/>
            <xsd:element name="EndYearMonth" type="YYMMType"/>
            <xsd:element name="EligibleTuitionFeeAmount" type="Decimal11AmountType" minOccurs="0"/>
            <xsd:element name="PartTimeStudentMonthCount" type="ZeroToTwelveCountType"/>
            <xsd:element name="FullTimeStudentMonthCount" type="ZeroToTwelveCountType"/>
        </xsd:all>
    </xsd:complexType>

    <xsd:complexType name="T2202SummaryType">
        <xsd:all>
            <xsd:element name="FilerAccountNumber" type="BNRZType"/>
            <xsd:element ref="SummaryReportTypeCode"/>
            <xsd:element name="FilerAmendmentNote" type="Length1to1309TextType" minOccurs="0"/>
            <xsd:element ref="TaxationYear"/>
            <xsd:element ref="TotalSlipCount"/>
            <xsd:element name="PostSecondaryEducationalInstitutionName" type="ThreeLinedLength30NameType"/>
            <xsd:element name="PostSecondaryEducationalInstitutionMailingAddress" type="RequiredLine1AddressType"/>
            <xsd:element name="ContactInformation" type="ContactType3" minOccurs="0"/>
            <xsd:element name="TotalEligibleTuitionFeeAmount" type="Decimal15AmountType"/>
        </xsd:all>
    </xsd:complexType>
</xsd:schema>

我需要验证xml文件。可以对xml文件进行少量更改。我收到以下错误

错误:元素“返回”:没有匹配的全局声明可用于验证根

提前致谢

查看更多

提问者
vnk
被浏览
45
zx485 2020-02-04 09:07

我调试了您的XSD集,并最终隔离了关键错误:

  1. 因此,可以将minOccurs="0"属性添加到您lemmcommontypes.xsd喜欢的以下元素中

    <xsd:element ref="AddressLine1Text" minOccurs="0" /> <!-- Added by edit -->
    

    这可能是不可能的,因为您不能更改XSD。

  2. 或者,否则,将以下元素添加为XML的一部分

    <PostSecondaryEducationalInstitutionMailingAddress>
        <AddressLine1Text>WHATEVER!!!</AddressLine1Text>   <!-- Added by edit -->
        <CityName>ABBOTSFORD</CityName>
        <ProvinceStateCode>BC</ProvinceStateCode>
        <CountryCode>CAN</CountryCode>
        <PostalZipCode>V2W3A9</PostalZipCode>
    </PostSecondaryEducationalInstitutionMailingAddress>
    
  3. 另外,将Decimal13AmountTypein 的定义更改lemmcommontypes.xsd

    <xsd:simpleType name="Decimal13AmountType">
        <xsd:restriction base="sdt:AmountType">
            <xsd:totalDigits value="13"></xsd:totalDigits>
            <xsd:pattern value="[+]?\d{0,11}(\.\d{2})?"/>
            <xsd:minInclusive value="0"/>
        </xsd:restriction>
    </xsd:simpleType>
    

    这可能是不可能的,因为您不能更改XSD。

  4. 或者,如果您不能执行此操作,请将值TotalEligibleTuitionFeeAmount更改为00.00以使RegEx匹配。

使XML与您的XSD集匹配。


在这两种情况下,您都必须在上述XSD文件(从中复制frms.xsd)中添加以下定义

<xsd:complexType name="T2202ReturnType">   <!-- From frms.xsd -->
    <xsd:sequence>
        <xsd:element name="T2202Slip" type="T2202SlipType" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element name="T2202Summary" type="T2202SummaryType"/>
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="ReturnChoiceType">  <!-- From frms.xsd -->
    <xsd:choice>
        <xsd:element name="T2202" type="T2202ReturnType" minOccurs="0"/>
    </xsd:choice>
</xsd:complexType>

<xsd:element name="Return" type="ReturnChoiceType"/>

使上述XML匹配。
现在,XML应该验证了。