all groups > dotnet xml > october 2003 >
You're in the

dotnet xml

group:

selective validation



selective validation RP
10/31/2003 10:47:06 AM
dotnet xml: Hi all, is it possible to validate only a particular node of a XML doc
against an XSD using XMLValidatingReader? Any links to sample code snippets
would be much appreciated.

TIA,
RP

Re: selective validation Oleg Tkachenko
10/31/2003 6:03:21 PM
[quoted text, click to view]

You can pretend the node represents XML document or XML fragment you
want to validate, then nothing special should be done. The only problem
is then in .NET 1.0 and 1.1 one cannot validate XmlDocument in-memory,
you have to get XML as text and then read it via XmlValidatingReader.
Something like

XmlTextReader r = new XmlTextReader(new StringReader(node.OuterXml));
XmlValidatingReader vr = new XmlValidatingReader(r);
vr.ValidationType = ValidationType.Schema;
while (vr.Read());

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
AddThis Social Bookmark Button