I am trying to validate xml file with xsd file for filing T2202 TAX SLIP for canada revenue agency
Below is my xml file which can be slightly changed for it to validate with xsd schema file.
<?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>
Please find below my xsd schema file which is from the government website.
<?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>
I need to validate the xml file.Slight changes can be made to xml file. I am getting the error below
ERROR: Element 'Return': No matching global declaration available for the validation root
Thanks in advance
I debugged the set of your XSDs and finally isolated the crucial errors:
So either add the minOccurs="0"
attribute to the following element in your lemmcommontypes.xsd
like
<xsd:element ref="AddressLine1Text" minOccurs="0" /> <!-- Added by edit -->
which is probably not possible, because you cannot change the XSD.
Or, otherwise, add the following element as part of your XML
<PostSecondaryEducationalInstitutionMailingAddress>
<AddressLine1Text>WHATEVER!!!</AddressLine1Text> <!-- Added by edit -->
<CityName>ABBOTSFORD</CityName>
<ProvinceStateCode>BC</ProvinceStateCode>
<CountryCode>CAN</CountryCode>
<PostalZipCode>V2W3A9</PostalZipCode>
</PostSecondaryEducationalInstitutionMailingAddress>
Also, change the definition of Decimal13AmountType
in lemmcommontypes.xsd
to
<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>
which is probably not possible, because you cannot change the XSD.
Or, if you cannot do this, change the value(s) TotalEligibleTuitionFeeAmount
from 0
to 0.00
to make the RegEx match.
to make the XML match your XSD set.
In both cases you have to add the following definitions to the above XSD file (which are copied from 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"/>
to make the above XML match.
Now the XML should validate.
Thanks for your time.XML is valid now by adding this code.But is there something I can add to xml file instead of changing xsd file? This is because while filing tax we need to use the proper xml. Changing the xsd is not an option.
As I wrote in the above answer: options 1 and 3 are changing the XSD and options 2 and 4 are changing the XML. So if you cannot change the XSD, use the options 2 and 4. That means adding the line
<AddressLine1Text>WHATEVER!!!</AddressLine1Text>
and changing0
to0.00
in your XML. Then add the definitions mentioned in the last part of the answer (after the list) to your XSD.I made changes to xml. But I am talking about "add the definitions mentioned in the last part of the answer (after the list) to your XSD" . This is kind of changing the xsd file right?
I had to add the last part (which I simply copied from the
frms.xsd
file) to make the whole situation you described in your question work. In a complete scenario you probably havefrms.xsd
included and hence the addition would not be neccessary. But to make this answer complete, it was. This is why I referred to the MCVE: to make the MCVE work, the last part has to be added."To validate your file, check both the format and content of an .xml file against our schema files using a validating parser." - I hope adding code from one file to another is fine.