472,805 Members | 944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

"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
6 13508
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lars | last post by:
I am trying to post a pretty long string (9300 bytes) in a hidden field and i get this very strange error message: Request object, ASP 0107 (0x800A01B8) The data being processed is over the...
0
by: mrwoopey | last post by:
Hi, My OLAP data cube is giving me the following error when I am manipulating OLAP data cube views: "the data being processed is over the allowed limit" I know that this message is caused by...
2
by: Bill Short | last post by:
Hello All, I have a popup form that is called from a command button on the main form. The main form's data source is tblA. The data source for the popup form is a query that is based on tblA. ...
1
by: acool | last post by:
I just created a simple Windows Service in VB.NET. I right clicked on the component and added the installer, installed via InstallUtil.exe all went well until i try to do a net start and then I...
7
by: Søren Dreijer | last post by:
Hi, I have a mixed C#, managed C++ and unmanaged C++ project. The managed class calls a method which exists in an unmanaged singleton class. During the entire lifetime of the application, this...
0
by: jens Jensen | last post by:
Hello, I'm trying to connect to a system via https. As an additional security measure, the server requires me to attach an x509 certs to my "HTTP POST" request. I get the error...
7
by: PW | last post by:
Hi, I have a form with unbound fields on it. The user selects a record from a recordset and I populate the unbound fields. When I try to change the unbound quantity text box, Access 2003 tells...
2
by: patrice.pare | last post by:
Hello, Here is a summary of my Dev Environment: I use Visual Studio 2005 Team Suite SP1 with Crystal Report XI SP1 on a Windows XP SP2 development workstation. I also use SQL Server 2000 SP4. ...
1
by: =?Utf-8?B?am1ncm8=?= | last post by:
I created a web service in visual studio 2003, tested it with a sample.xml file from a vendor we are using, and it worked exactly like it should. I deployed it to our server, created a project...
3
by: zhif | last post by:
Hello everybody, I am trying to export the data from DB2 database to MySQL. The command I used is db2 "export to sys_state.del of del modified coldel; select * from sys_state" But, I...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.