Sign In/My Account | View Cart  
advertisement

Article:
 XML Data-Binding: Comparing Castor to .NET
Subject: validation in .Net?
Date: 2002-08-05 17:54:25
From: Niel Bornstein
Response to: validation in .Net?

It's a fair question, and one which I did not address in this article.


Basically, the validation of an XML document with a particular schema is done with XmlValidatingReader. One approach might be to create an instance of the DogShow class, then use XmlSerializer to write it to a MemoryStream. Then create an XmlValidatingReader, set its ValidationType to ValidationType.Schema, add the schema to its XmlSchemaCollection, and call Read().


The following code snippet, replacing the XmlWriter portion of the C# sample, should provide some direction:


Stream stream = new MemoryStream();
TextWriter writer = new StreamWriter(stream);
serializer.Serialize(writer,show);


stream.Seek(0,SeekOrigin.Begin);


XmlValidatingReader reader = new XmlValidatingReader(new XmlTextReader(stream));
reader.ValidationType = ValidationType.Schema;
reader.Schemas.Add("", "DogShow.xsd");


while (reader.Read()) {
// do nothing
}


No Previous Message Previous Message Move up to Parent Message Up Next Message No Next Message


Sponsored By: