467,858 Members | 1,326 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,858 developers. It's quick & easy.

"the data at the root level is invalid" "line 1, position 1."

TS
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();

}

}
Nov 12 '05 #1
  • viewed: 13226
Share:
6 Replies
TS
when i run it thru http://tools.decisionsoft.com/schemaValidate.html it
says:
1.. Cannot find the declaration of element 'ReportInfo'.
"TS" <ma**********@nospam.nospam> wrote in message
news:ug*************@TK2MSFTNGP09.phx.gbl...
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();

}

}

Nov 12 '05 #2


TS wrote:

<xs:schema id="ReportInfo" targetNamespace="http://tempuri.org/Reports.xsd"
Here you declare that the target namespace of your schema is
http://tempuri.org/Reports.xsd meaning you want to define elements in a
namespace with the URI http://tempuri.org/Reports.xsd.
But your XML here
<ReportInfo>


does not declare the namespace, you need e.g.
<ReportInfo xmlns="http://tempuri.org/Reports.xsd">
or
<rp:ReportInfo xmlns:rp="http://tempuri.org/Reports.xsd">
to have an XML document complying with what the schema describes.

That is at least one major error you need to fix, I haven't looked
further whether anything else is wrong.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #3
TS
thanks for the response!

I added that, and still it gives same error
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...


TS wrote:

<xs:schema id="ReportInfo"
targetNamespace="http://tempuri.org/Reports.xsd"
Here you declare that the target namespace of your schema is
http://tempuri.org/Reports.xsd meaning you want to define elements in a
namespace with the URI http://tempuri.org/Reports.xsd.
But your XML here
<ReportInfo>


does not declare the namespace, you need e.g.
<ReportInfo xmlns="http://tempuri.org/Reports.xsd">
or
<rp:ReportInfo xmlns:rp="http://tempuri.org/Reports.xsd">
to have an XML document complying with what the schema describes.

That is at least one major error you need to fix, I haven't looked
further whether anything else is wrong.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Nov 12 '05 #4
Hi TS,

Thanks for posting your code here.

Based on my research, there are 2 problems here.

1. In your code you used xmlDoc.ToString(). The ToString method returns
"System.Xml.XmlDocument" instead of the content of the xml document. So we
have to use OuterXml property instead. Here is an example.

XmlTextReader xmlReader = new XmlTextReader(xmlDoc.OuterXml,
XmlNodeType.Document, context);

2. In the Xml document, we have to add the schema location in the root
element. Here is an example if the xml file and xsd file are in the same
directory.

<ReportInfo xmlns="http://tempuri.org/Reports.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tempuri.org/Reports.xsd">

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #5
TS
thanks, it appears that all i needed was the .outerXml
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:fU*************@TK2MSFTNGXA01.phx.gbl...
Hi TS,

Thanks for posting your code here.

Based on my research, there are 2 problems here.

1. In your code you used xmlDoc.ToString(). The ToString method returns
"System.Xml.XmlDocument" instead of the content of the xml document. So we
have to use OuterXml property instead. Here is an example.

XmlTextReader xmlReader = new XmlTextReader(xmlDoc.OuterXml,
XmlNodeType.Document, context);

2. In the Xml document, we have to add the schema location in the root
element. Here is an example if the xml file and xsd file are in the same
directory.

<ReportInfo xmlns="http://tempuri.org/Reports.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tempuri.org/Reports.xsd">

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #6
You're welcome.

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by SÝren Dreijer | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.