如何使用Saxon Home Edition(HE)9.4来针对XSD验证XML?
我是否需要企业版才能执行此基本操作,这是错误消息所暗示的内容?这是我正在使用的代码。
private void btnSaxonTest3_Click(object sender, EventArgs e)
// validate xml against xsd and show multiple errors
{
try
{
SetGlobalVariables();
Saxon.Api.Processor proc = new Processor(true);
//this is the property to set for multiple errors
//proc.SetProperty("net.sf.saxon.lib.FeatureKeys.VALIDATION_WARNINGS", "true"); //Enterprise function only?
SchemaManager schemaManager = proc.SchemaManager;
FileStream xsdFs = new FileStream(GvXSDFullPath, FileMode.Open);
schemaManager.Compile(XmlReader.Create(xsdFs));
SchemaValidator validator = schemaManager.NewSchemaValidator();
FileStream xmlFs = new FileStream(GvXMLFullPath, FileMode.Open);
validator.SetSource(XmlReader.Create(xmlFs));
validator.ErrorList = new ArrayList();
try
{
validator.Run();
}
catch (Exception)
{
AddMsg("Instance validation failed with " + validator.ErrorList.Count + " errors");
foreach (StaticError error in validator.ErrorList)
{
AddMsg("At line " + error.LineNumber + ": " + error.Message);
}
txtResults.Text = GvResults;
return;
} // try catch
}
catch (Exception ex)
{
AddMsg(ex.ToString());
}
AddMsg("Process completed");
txtResults.Text = GvResults;
}