Hi, i have a problem validating xml against schema. I used
http://apps.gotdotnet.com/xmltools/x...r/Default.aspx validator and
it says it is fine. Can you tell me why this doesn't work?
Thanks!
Schema:
<?xml version="1.0"?>
<xs:schema id="ReportInfo" targetNamespace="http://tempuri.org/Reports.xsd"
xmlns:mstns="http://tempuri.org/Reports.xsd"
xmlns="http://tempuri.org/Reports.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="ReportInfo" msdata:IsDataSet="true"
msdata:EnforceConstraints="False">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Categories">
<xs:complexType>
<xs:sequence>
<xs:element name="Category" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="id" form="unqualified" type="xs:string" />
<xs:attribute name="name" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="UserTypes">
<xs:complexType>
<xs:sequence>
<xs:element name="UserType" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="id" form="unqualified" type="xs:string" />
<xs:attribute name="name" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Reports">
<xs:complexType>
<xs:sequence>
<xs:element name="Report" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Title" type="xs:string" minOccurs="0" msdata:Ordinal="0"
/>
<xs:element name="Description" type="xs:string" minOccurs="0"
msdata:Ordinal="1" />
<xs:element name="ParameterSections" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Section" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Parameters" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Parameter" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Properties" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Property" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" form="unqualified" type="xs:string" />
<xs:attribute name="value" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" form="unqualified" type="xs:string" />
<xs:attribute name="type" form="unqualified" type="xs:string" />
<xs:attribute name="controlTypeName" form="unqualified" type="xs:string" />
<xs:attribute name="controlPath" form="unqualified" type="xs:string" />
<xs:attribute name="variableType" form="unqualified" type="xs:string" />
<xs:attribute name="variableKey" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="repeatDirection" form="unqualified" type="xs:string" />
<xs:attribute name="repeatColumns" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="userTypeID" form="unqualified" type="xs:string" />
<xs:attribute name="categoryID" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="controlPath" form="unqualified" type="xs:string" />
<xs:attribute name="controlAssemblyTypeName" form="unqualified"
type="xs:string" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
xml file:
<?xml version="1.0" encoding="utf-8" ?>
<ReportInfo>
<Categories>
<Category id="table" name="Table Reports" />
</Categories>
<UserTypes>
<UserType id="TEA" name="TEA User" />
<UserType id="TexasLearns" name="Texas Learns User" />
</UserTypes>
<Reports controlPath="~/ReportControls"
controlAssemblyTypeName="TEA.Teams.Web">
<Report name="Table4">
<Title>Table IV</Title>
<Description>This report contains a participant's progress.</Description>
<ParameterSections>
<Section userTypeID="TEA" categoryID="table">
<Parameters repeatDirection="Horizontal" repeatColumns="1">
<Parameter name="@StandardCriteria" type="CustomControl"
controlTypeName="TEA.Teams.Web.ReportControls.Stan dardCriteria" />
<Parameter name="@FiscalAgentHierarchy" type="CustomControl"
controlTypeName="TEA.Teams.Web.ReportControls.Fisc alAgentHierarchy" />
<Parameter name="@ProfileCriteria" type="CustomControl"
controlTypeName="TEA.Teams.Web.ReportControls.Prof ileCriteria">
<Properties>
<Property name="Visible" value="True" />
</Properties>
</Parameter>
<Parameter name="@Validated" type="Control"
controlPath="ValidateCheckBox.ascx" />
<Parameter name="@StateComputation" type="Control"
controlPath="ComputationMethodDropDown.ascx" />
</Parameters>
</Section>
<Section userTypeID="Grantee" categoryID="grantee">
<Parameters repeatDirection="Horizontal" repeatColumns="1">
<Parameter name="@GranteeIDs" type="Variable" variableType="SessionValue"
variableKey="CCLCPageBase_GranteeID" />
<Parameter name="@CycleYears" type="Control"
controlPath="CycleYearMultiList.ascx" />
<Parameter name="@SchoolYear" type="CustomControl"
controlTypeName="TEA.Teams.Web.ReportControls.Scho olYearReportSelector">
<Properties>
<Property name="Visible" value="True" />
</Properties>
</Parameter>
</Parameters>
</Section>
</ParameterSections>
</Report>
</Reports>
</ReportInfo>
Code:
XmlParserContext context = new XmlParserContext(null, new
XmlNamespaceManager(new NameTable()), null, XmlSpace.None);
XmlTextReader xmlReader = new XmlTextReader(xmlDoc.ToString(),
XmlNodeType.Document, context);
XmlValidatingReader objValidator = new XmlValidatingReader(xmlReader);
objValidator.ValidationType = ValidationType.Schema;
XmlSchemaCollection objSchemaCol = new XmlSchemaCollection();
objSchemaCol.Add(null, schemaPath.AbsolutePath);
objValidator.Schemas.Add(objSchemaCol);
objValidator.ValidationEventHandler += new
ValidationEventHandler(ValidationError);
try
{
while (objValidator.Read()) { }
}
catch(Exception objError)
{
throw new Exception(string.Format("Read/Parser error: {0}",
objError.Message));
}
finally
{
xmlReader.Close();
}
}