1
如何使用Saxon Home Edition(HE)9.4對XSD驗證XML?如何使用Saxon Home Edition(HE)驗證XML與XSD的關係9.4
我是否需要企業版來做這個基本的事情,這就是錯誤信息所暗示的意思?這是我正在使用的代碼。
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;
}
謝謝,我希望這是情況並非如此。我喜歡.NET Schematron實現如何允許我將標記添加到XSD文件並進行基本的業務規則驗證。聽起來像我不得不花費現金與撒克遜人做這件事。 – user610064 2012-03-13 16:46:53