have been trying things out and found an interesting article at
http://support.microsoft.com/kb/307379/EN-US/
but somehow, the code given prompted me more errors than i can understand, making the whole thing useless. Any other better recomendation?
One thing from the article made me think for a while. Is it a must that the link to an xsd file have to be stored inside the xml file?
Validate xml with schemas... try this :)
string strPath = Application.StartupPath + @"\Sample.xml";
XmlSchema schema = XmlSchema.Read(
ValidationEventHandler handler =
XmlTextReader reader;
XmlValidatingReader valid;
{
reader =
valid =
valid.Schemas.Add(schema);
valid.ValidationType = ValidationType.Schema;
}
lstResult.Items.Add("XML Script contains no errors");
lstResult.Items.Add("XML Error " + ex.Message);
schema =
-----------
I believe it is not ncessary. I have tested it here. The only reason why the xsd link is in the xml file is because when you create a schema from a xml in VS.NET, it will auto include the link in that xml.
Hope it helps you somehow :)
HoeKeat wrote: One thing from the article made me think for a while. Is it a must that the link to an xsd file have to be stored inside the xml file?
If you have link the XSD file from the XML file appropriately, then when you validate using XmlValidatingReader, you don't have to add the schema anymore.
The following line is unnecessary if you have the link.
Maung Maung