views:

341

answers:

3

I am trying to validate xml file against schema using XML::Validator::Schema.
But it gives me this error:

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

Note: <Submission> is the very first element I have after <xml version="1.0" encoding="UTF-8"?>

I can't figure out what it means.
Appreciate any help.

XML is:

<?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 is:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    <!-- @@@@ 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>
+1  A: 

Looks like you don't have a submission element in your xsd. I also don't see a return element. You want to define that.

On another note, Paul, thanks for getting me hired at my first job and taking me flying.

MattK
A: 

[This post has been moved to the question, where it belonged.]

Thushan
I have to tell you you have chosen awful names for your elements. What the hell would gro_2_incamt mean? Elements are intended to be more comprehensible than that.
Leon Timmermans
We should tell that to Canada Revenue Agency (CRA). ;)It's there schema.
Thushan
Rick, that "edit" link at the bottom of your post is there for a reason. This information belongs in the question; it's not an answer.
cjm
+2  A: 

You have defined several types, but you have not defined any elements (except those defined as sub-components of the types you have defined). Not only is <Submission> not defined, neither is <Return> (which is its immediate child-element) nor any of <NR4>, <NR4Slip>, etc.

You'll need a series of <xsd:element> blocks to map the types you've defined to actual elements/tags. (As well as declarations for <Return> and <NS4>, but since those seem to only appear within <Submission>, you may want to just declare them in-line as part of the declaration of <Submission>.)

Here is a stab at a declaration for <Submission> that uses your existing types, but declares the other elements in-line. This is wholly un-tested, top-of-my-head, typed on public wi-fi while on vacation without my copy of ORA's "XML Schema" on hand:

<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>

This doesn't put any bounds on the number of <NR4Slip> or <NR4Summary> blocks you can have; you might want to set that with minOccurs and/or maxOccurs attributes on the inner-most <xsd:element> tags. The inline declarations also bypass actually mapping NR4SlipType or NR4SummaryType to elements.

rjray