473,387 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Trying to validate XML w/ an XSD..

I'm trying to validate an XmlDocument with an XSD schema,
and I'm getting the following error:

Could not find schema information for the
element 'month'. An error occurred at , (1, 40).

Here is the code I'm using for validation:

System.Text.UTF8Encoding utf8 = new
System.Text.UTF8Encoding(false);

XmlTextReader xr = null;
XmlValidatingReader vr = null;
xr = new XmlTextReader(Server.MapPath
("progressoverview.xsd"));

vr = new XmlValidatingReader(xr);
System.Xml.Schema.ValidationEventHandler schemaval = new
System.Xml.Schema.ValidationEventHandler
(this.val_ValidationEventHandler);

System.Xml.Schema.XmlSchema sch =
System.Xml.Schema.XmlSchema.Read(vr, schemaval);

sch.Compile(schemaval);
System.IO.MemoryStream mem = new System.IO.MemoryStream
(utf8.GetBytes(doc.OuterXml));

System.Xml.XmlTextReader rdr = new XmlTextReader(mem);
System.Xml.XmlValidatingReader val = new
XmlValidatingReader(rdr);

val.Schemas.Add(sch);
val.ValidationType = ValidationType.Schema;
val.ValidationEventHandler += schemaval;
while(val.Read())
{
System.Diagnostics.Debug.WriteLine(val.Name);
}
private void val_ValidationEventHandler(object sender,
System.Xml.Schema.ValidationEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}

-----

Here is my XML:

<?xml version="1.0" encoding="utf-8" ?>
<month number="1" type="month">
<week id="1">

</week>
</month>

-----

Here is my XSD:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="progressoverview"
targetNamespace="http://tempuri.org/progressoverview.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/progressoverview.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="month">
<xs:complexType>
<xs:sequence>
<xs:element name="week" minOccurs="1"
maxOccurs="4">
<xs:complexType>
<xs:sequence>
<xs:element name="day"
minOccurs="1" maxOccurs="7">
<xs:complexType>
<xs:attribute
name="id" type="xs:positiveInteger" />
<xs:attribute
name="status" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id"
type="xs:positiveInteger" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="number"
type="xs:positiveInteger" />
<xs:attribute name="type" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:schema>
-----
Any info on this would be most helpful...thanks!

Jonas


Nov 12 '05 #1
1 2107
Jonas Bush wrote:
I'm trying to validate an XmlDocument with an XSD schema,
and I'm getting the following error:

Could not find schema information for the
element 'month'. An error occurred at , (1, 40). <?xml version="1.0" encoding="utf-8" ?>
<month number="1" type="month"> <?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="progressoverview"
targetNamespace="http://tempuri.org/progressoverview.xsd"


This schema defines elements in
"http://tempuri.org/progressoverview.xsd" namespace, while your XML is
in no namespace. To make the XML be validated against this schema it
must be in the namespace the schema defines:
<month number="1" type="month"
xmlns="http://tempuri.org/progressoverview.xsd">
<week id="1">

</week>
</month>

--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike:o | last post by:
I need to validate XML documents (orders) against their schema before processing. The PurchaseOrder schema that we use references 3 other schemas using the <imports ...> element. Here is the...
1
by: Ron Rohrssen | last post by:
I've been working on learning XML schemas and trying to make use of the MS classes for validating data against a schema. So, I've been trying to work through some simple schemas and instances....
5
by: Jim Heavey | last post by:
When should you use the Page.Validate() method? I thought you would use this method if you have some Server side validation (CustomControl's) you wanted to use and this would cause them to be...
12
by: Jim Anderson | last post by:
This is my first attempt at XML documentation. I'm trying to get started with docbook so I can put a set of documentation into docbook tags. I'm using 'XML In A Nutshell" and "DocBook The...
11
by: jjbutera | last post by:
I know how to use the ErrorProvider in my winforms..or do I? I validate the values and set the ErrorProvider in the validating event. If not valid, I set e.Cancel = True. I clear the ErrorProvider...
10
by: Carlos Araya | last post by:
I have the following link on a web page <p class="menuitem"><a href="#" onclick="loadFragment('http://rivendellweb.net/fortress/home', 'index')" title="The Fortress Home">The Fortress...
2
by: Rahul | last post by:
I am trying the following thing in AJAX <atlas:ScriptManager ID="scriptmanager1" runat="Server" EnablePartialRendering="true" /> <asp:DropDownList ID="cmbBranchname" cssclass="Combostyle"...
0
by: Marc Scheuner | last post by:
Folks, I'm faced with a dilemma here - I have an XML document and for part of it, I have an XSD schema to validate it - but not for the rest of it. Can I still validate at least part of the...
8
by: Greg C. | last post by:
I tried tackling this problem about 6 months ago, but after going almost completely insane I gave up, since my news feed seemed to display just fine anyways. However, in an effort to have my feeds...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.