-1

我正在尝试使用XML::Validator::Schema针对架构验证 xml 文件。
但它给了我这个错误:

Found unexpected <Submission> inside <<<<ROOT>>>>.  This is not a valid child element. [Ln: 2, Col:119]

注意:<Submission>是我之后的第一个元素<xml version="1.0" encoding="UTF-8"?>

我不明白这意味着什么。
感谢任何帮助。

XML 是:

<?xml version="1.0" encoding="utf-8"?>
<Submission xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="layout-topologie.xsd">
 <Return>
  <NR4>
   <NR4Slip>
    <RCPNT_NM>
     <snm>SYMPSOM</snm>
     <gvn_nm>HOMER</gvn_nm>
     <init>A</init>
    </RCPNT_NM>
    <SEC_RCPNT_NM></SEC_RCPNT_NM>
    <RCPNT_ADDR>
     <addr_l1_txt>C/O ABC A/C 555 6666</addr_l1_txt>
     <addr_l2_txt>9999 - 88 STREET</addr_l2_txt>
     <cntry_cd>CAN</cntry_cd>
     <fgn_pstl_cd>T4S1M5</fgn_pstl_cd>
    </RCPNT_ADDR>
    <fssn_nbr>607-448-900</fssn_nbr>
    <nr_acct_nbr>NRY454080</nr_acct_nbr>
    <rcpnt_tcd>01</rcpnt_tcd>
    <payr_nbr>100000</payr_nbr>
    <inc_1_tcd>11</inc_1_tcd>
    <crcy_1_cd>CAD</crcy_1_cd>
    <tx_xmpt_1_cd>AB</tx_xmpt_1_cd>
    <inc_2_tcd>02</inc_2_tcd>
    <crcy_2_cd>CAD</crcy_2_cd>
    <tx_xmpt_2_cd>PQ</tx_xmpt_2_cd>
    <NR4_AMT>
     <gro_1_incamt>1.1</gro_1_incamt>
     <nr_tx_1_amt>0.00</nr_tx_1_amt>
     <gro_2_incamt>90000000</gro_2_incamt>
     <nr_tx_2_amt>0.00</nr_tx_2_amt>
    </NR4_AMT>
    <rpt_tcd>O</rpt_tcd>
   </NR4Slip>
   <NR4Slip>
    <RCPNT_NM>
     <snm>CARTMAN</snm>
     <gvn_nm>ERIC</gvn_nm>
    </RCPNT_NM>
    <SEC_RCPNT_NM>
     <sec_snm>SYMPSON</sec_snm>
     <sec_gvn_nm>BART</sec_gvn_nm>
    </SEC_RCPNT_NM>
    <RCPNT_ADDR>
     <addr_l1_txt>C/O DEFG A/C 555 2222</addr_l1_txt>
     <addr_l2_txt>9999 - 88 STREET</addr_l2_txt>
     <cntry_cd>CAN</cntry_cd>
     <fgn_pstl_cd>T4S1M5</fgn_pstl_cd>
    </RCPNT_ADDR>
    <fssn_nbr>607-448-901</fssn_nbr>
    <nr_acct_nbr>NRY454080</nr_acct_nbr>
    <rcpnt_tcd>01</rcpnt_tcd>
    <payr_nbr>200000</payr_nbr>
    <inc_1_tcd>11</inc_1_tcd>
    <crcy_1_cd>USD</crcy_1_cd>
    <tx_xmpt_1_cd>BC</tx_xmpt_1_cd>
    <inc_2_tcd>02</inc_2_tcd>
    <crcy_2_cd>USD</crcy_2_cd>
    <tx_xmpt_2_cd>QR</tx_xmpt_2_cd>
    <NR4_AMT>
     <gro_1_incamt>20.01</gro_1_incamt>
     <nr_tx_1_amt>10</nr_tx_1_amt>
     <gro_2_incamt>8000000</gro_2_incamt>
     <nr_tx_2_amt>0.1</nr_tx_2_amt>
    </NR4_AMT>
    <rpt_tcd>O</rpt_tcd>
   </NR4Slip>
   <NR4Summary>
    <PAYR_NM>
     <l1_nm>THE BANK OF NOVA SCOTIA</l1_nm>
    </PAYR_NM>
    <PAYR_ADDR>
     <addr_l1_txt>HR SHARED SERVICES PENSION DEPT.</addr_l1_txt>
     <addr_l2_txt>7TH FLOOR, 888 BIRCHMOUNT ROAD</addr_l2_txt>
    </PAYR_ADDR>
    <tx_yr>2007</tx_yr>
    <slp_cnt>10</slp_cnt>
   </NR4Summary>
  </NR4>
 </Return>
</Submission>

XSD 是:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <!-- @@@@ Definition of NR4  ComplexTypes @@@@  2008/sept/03  Version# 2.8  -->
    <xsd:complexType name="NR4SlipType">
        <xsd:all>
            <xsd:element name="RCPNT_NM" type="NameType" minOccurs="0"/>
            <xsd:element name="SEC_RCPNT_NM" type="NameType_2" minOccurs="0"/>
            <xsd:element name="ENTPRS_NM" type="NR4_Line2Type" minOccurs="0"/>
            <xsd:element name="RCPNT_ADDR" type="NR4ForeignAddressType" minOccurs="0"/>
            <xsd:element name="tx_cntry_cd" type="char3Type"/>
            <xsd:element name="fssn_nbr" type="char20Type"/>
            <xsd:element name="nr_acct_nbr" type="nrType"/>
            <xsd:element name="rcpnt_tcd" type="indicator1-5Type"/>
            <xsd:element name="payr_nbr" type="char20Type" minOccurs="0"/>
            <xsd:element name="inc_1_tcd" type="numeric2Type" minOccurs="0"/>
            <xsd:element name="crcy_1_cd" type="char3Type" minOccurs="0"/>
            <xsd:element name="NR4_AMT" type="NR4AmountType" minOccurs="0"/>
            <xsd:element name="tx_xmpt_1_cd" type="char1Type" minOccurs="0"/>
            <xsd:element name="inc_2_tcd" type="numeric2Type" minOccurs="0"/>
            <xsd:element name="crcy_2_cd" type="char3Type" minOccurs="0"/>
            <xsd:element name="tx_xmpt_2_cd" type="char1Type" minOccurs="0"/>
            <xsd:element name="rpt_tcd" type="slipDataType"/>
        </xsd:all>
    </xsd:complexType>
    <xsd:complexType name="NR4AmountType">
        <xsd:all>
            <xsd:element name="gro_1_incamt" type="decimal11Type" minOccurs="0"/>
            <xsd:element name="nr_tx_1_amt" type="decimal11Type" minOccurs="0"/>
            <xsd:element name="gro_2_incamt" type="decimal11Type" minOccurs="0"/>
            <xsd:element name="nr_tx_2_amt" type="decimal11Type" minOccurs="0"/>
        </xsd:all>
    </xsd:complexType>
    <xsd:complexType name="NR4SummaryType">
        <xsd:all>
            <xsd:element name="nr_acct_nbr" type="nrType"/>
            <xsd:element name="PAYR_NM" type="Line3Type"/>
            <xsd:element name="PAYR_ADDR" type="NR4CanadaAddressType" minOccurs="0"/>
            <xsd:element name="CNTC" type="ContactType2"/>
            <xsd:element name="tx_yr" type="yearType"/>
            <xsd:element name="slp_cnt" type="int7Type"/>
            <xsd:element name="rmt_tcd" type="indicator1-2Type" minOccurs="0"/>
            <xsd:element name="rpt_tcd" type="otherDataType"/>
            <xsd:element name="NR4_TAMT" type="NR4TotalsType" minOccurs="0"/>
        </xsd:all>
    </xsd:complexType>
    <xsd:complexType name="NR4TotalsType">
        <xsd:all>
            <xsd:element name="tot_gro_1_incamt" type="decimal13Type" minOccurs="0"/>
            <xsd:element name="tot_nr_tx_1_amt" type="decimal13Type" minOccurs="0"/>
            <xsd:element name="tot_gro_2_incamt" type="decimal13Type" minOccurs="0"/>
            <xsd:element name="tot_nr_tx_2_amt" type="decimal13Type" minOccurs="0"/>
            <xsd:element name="tot_nrpt_incamt" type="decimal13Type" minOccurs="0"/>
            <xsd:element name="tot_nr_nrpt_tx_amt" type="decimal13Type" minOccurs="0"/>
        </xsd:all>
        <xsd:attribute name="tot_incamt" type="xsd:string"/>
        <xsd:attribute name="tot_tx_wthld" type="xsd:string"/>
    </xsd:complexType>
</xsd:schema>
4

2 回答 2

2

您已经定义了几种类型,但是您还没有定义任何元素(除了那些定义为您定义的类型的子组件的元素)。不仅<Submission>没有定义,也没有定义<Return>(这是它的直接子元素),也没有定义<NR4><NR4Slip>等等。

您需要一系列<xsd:element>块来将您定义的类型映射到实际的元素/标签。(以及 and 的声明<Return><NS4>但由于它们似乎只出现在 内<Submission>,您可能只想将它们内联声明为 的声明的一部分<Submission>。)

这是一个声明,<Submission>它使用您现有的类型,但内联声明其他元素。这是完全未经测试的,在我头上的,在我手头没有 ORA 的“XML Schema”副本的情况下在公共 wi-fi 上输入的:

<xsd:element name="Submission" nillable="false">
  <xsd:complexType>
    <xsd:sequence maxOccurs="1" minOccurs="1">
      <xsd:element name="Return">
        <xsd:complexType>
          <xsd:sequence maxOccurs="1" minOccurs="1">
            <xsd:element name="NS4">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="NR4Slip" type="NR4SlipType" />
                  <xsd:element name="NR4Summary" type="NR4SummaryType" />
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>
</xsd:element>

这不会限制您可以拥有的数量<NR4Slip>或块数;<NR4Summary>您可能希望在最里面的标签上使用minOccurs和/或属性来设置它。内联声明也绕过实际映射或到元素。maxOccurs<xsd:element>NR4SlipTypeNR4SummaryType

于 2008-11-26T18:36:09.910 回答
1

看起来您的 xsd 中没有提交元素。我也没有看到返回元素。你想定义它。

另一方面,保罗,感谢您让我在第一份工作中被录用并带我飞翔。

于 2008-11-26T16:46:27.290 回答