473,387 Members | 1,650 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.

how to use xsd proof xml-string from xmldocument

I have a xmldocument like this:

XmlDocument doc = new XmlDocument();
doc.LoadXml(xml-string);

and I have a .xsd file, "schema.xsd".

How do I use this xsd file to valid the string?
Otherwise how do I trans the doc to XmlTextReader and valid it?
Thanks for any advice, David.

Nov 16 '05 #1
3 1632
"David" <ca*******@walla.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com...
How do I use this xsd file to valid the string?


using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;
// . . .

private bool isSchemaValid;

// . . .
private void btnValidate_Click( object sender, EventArgs args)
{
// . . .
this.isSchemaValid = true;
string targetNamespaceURI = "urn:your-schema-com"; // put the target namespace URI of your schema here.
XmlValidatingReader reader = new XmlValidatingReader( new XmlTextReader( new StringReader( xml_string ) ) );
reader.Schemas.Add( targetNamespaceURI, "schema.xsd");
reader.ValidationEventHandler += new ValidationEventHandler( xmlDocument1_ValidationCallBack);

XmlDocument xmlDocument1 = new XmlDocument( );
xmlDocument1.Load( reader); // this will call Read( ) on the XmlValidatingReader, which schema-validates as it loads.
// . . .
// . . . any schema errors will result in the callback method being called while Load( ) processes.
// . . .
Console.WriteLine( "\r\n\tSchemaValid = " + this.isSchemaValid.ToString( ) );
// . . .
}
// . . .
private void xmlDocument1_ValidationCallBack( object sender, ValidationEventArgs args)
{
isSchemaValid = false;
Console.WriteLine( "\r\n\tValidation Error: " + args.Message );
}
Derek Harmon
Nov 16 '05 #2
Thank you very much.

David.

Nov 16 '05 #3
Thank you, Derek.

If I wrote it in .dll and deploy it to another server,
how should I assign the xsd file path in reader.Schemas.Add(
targetNamespaceURI, "schema.xsd")?

Thanks, David.

Nov 16 '05 #4

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

Similar topics

10
by: nop90 | last post by:
Proof of concept: Currently I have a web hosting service and it does support php. Can the following be done in php? Explanations or examples would be appreciated. Create 2 applications, app-1...
34
by: Justin Timberlake | last post by:
I was thinking about all those /Indian Outsourcing/ companies getting those .Net shops set up. 0. Nobody uses .NET in the real world, it's all java. 1. MSFT is about to collapse as witnessed by...
4
by: deko | last post by:
I've created an mde out of my mdb in and effort to prevent users from changing settings/forms/etc. But I've discovered that the database window is still available if I hold down the Shift key when...
17
by: Edwin Knoppert | last post by:
I know ASP.NET 1.x generated dll's which decompilable to plain c or vb (afaik, i never used 2003) Is this problem solved in 2005? We ever want to distribute 2005 compiled code. And it seems all...
43
by: SLH | last post by:
hi people. im trying to validate input received via a text area on an ASP page before writing it to a database. i cant use client side javascript due to policy, so it all has to happen on the...
2
by: Anton Vredegoor | last post by:
For the last few days I've been doodling with a script that provides a graphical interface to gnugo by using its GTP protocol. At the moment the script is *very* basic, in fact the only thing it...
0
by: mantaintai | last post by:
Proof of visual consciousness visual consciousness image formation by a plane mirror , visual consciousness, transform, virtual image , overlap(superpose), dual identities, seeing an object ...
4
by: Doug Gray | last post by:
Folks, I am looking for a fast but most importantly a bullet proof method to pass and NMEA data stream (GPS output) ascii numeric strings. The best I can offer is: def fint(a): try: return...
15
bartonc
by: bartonc | last post by:
I don't have time for such things as puzzles, but there is Proof that Python Programmers are Smarter
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.