I have an XSD file and an XML file, how can I check if the XML is in the right schema like the XSD file?
i know there is an validate function in the XmlDocument
class, but it needs an event handler
and all I need is true or false.
P.S. I'm working inVisual Studio 2010.
There is a much easier way to do it:
private void ValidationCallBack(object sender, ValidationEventArgs e)
{
throw new Exception();
}
public bool validate(string sxml)
{
try
{
XmlDocument xmld=new XmlDocument ();
xmld.LoadXml(sxml);
xmld.Schemas.Add(null,@"c:\the file location");
xmld.validate(ValidationCallBack);
return true;
}
catch
{
return false;
}
}
P.S : I didn't write this in VS so there might be a word that does not have the right case sensitivity, but this code works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With