473,811 Members | 1,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1655
"David" <ca*******@wall a.com> wrote in message news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
How do I use this xsd file to valid the string?


using System;
using System.IO;
using System.Xml;
using System.Xml.Sche ma;
// . . .

private bool isSchemaValid;

// . . .
private void btnValidate_Cli ck( object sender, EventArgs args)
{
// . . .
this.isSchemaVa lid = true;
string targetNamespace URI = "urn:your-schema-com"; // put the target namespace URI of your schema here.
XmlValidatingRe ader reader = new XmlValidatingRe ader( new XmlTextReader( new StringReader( xml_string ) ) );
reader.Schemas. Add( targetNamespace URI, "schema.xsd ");
reader.Validati onEventHandler += new ValidationEvent Handler( xmlDocument1_Va lidationCallBac k);

XmlDocument xmlDocument1 = new XmlDocument( );
xmlDocument1.Lo ad( reader); // this will call Read( ) on the XmlValidatingRe ader, which schema-validates as it loads.
// . . .
// . . . any schema errors will result in the callback method being called while Load( ) processes.
// . . .
Console.WriteLi ne( "\r\n\tSchemaVa lid = " + this.isSchemaVa lid.ToString( ) );
// . . .
}
// . . .
private void xmlDocument1_Va lidationCallBac k( object sender, ValidationEvent Args args)
{
isSchemaValid = false;
Console.WriteLi ne( "\r\n\tValidati on 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(
targetNamespace URI, "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
2340
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 and app-2 app-1 loops continuosly. Every 1 second the application writes the time of day to a file.
34
2420
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 Bill Gate$ selling his stock in droves. 2. Linux marketshare is eating up windos. So when all is said and done, the wogs won't have much left for them, will they?
4
1734
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 opening the mde. Forms can no longer be opened in Design View, which is good, but queries and tables are still vulnerable. I've unchecked "Display Database Window" in Tools >> Start Up, but that does not seem to help if the Shift key is held...
17
1410
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 like ordinary dll's at first. Is the code i wrote retrievable? Thanks!
43
2626
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 server. here is what i was trying, but pieces of it continue to break for one reason or another. the thinking behind this function was like this: if the input is less than 10 characters long, fail. if its 10 characters or greater, but it doesnt...
2
1369
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 does is to allow one to click on a coordinate and place a move there OR press the space bar in order to let gnugo generate a move. However, I feel that this idea has some potential, it could be made to undo or redo moves or load sgf-games. But...
0
282
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 How could an object become visible when observed by the eyes of the human beings, i.e., how could the electrochemical changes of the visual cortex and cerebral cortex be transformed into an object?
4
2270
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 int(float(a)) except: return 0 The reason for this is the quality of the data from the huge variety of
15
1918
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
9728
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10648
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10389
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10135
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9205
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7670
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3867
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.