我正在使用验证XML文件的C#应用程序。到目前为止,我已设法实现单DTD或XSD验证,以及检查格式良好。
当前验证码
// get the path for current XML that should be validated
string xmlPath = listView.Items[currentItemIndex].SubItems[Form1.index_fileName].Text;
// set up the XML reader settings
XmlReaderSettings config = new XmlReaderSettings();
config.ValidationType = ValidationType.DTD;
config.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
config.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
config.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
config.DtdProcessing |= DtdProcessing.Parse;
config.ValidationEventHandler += Config_ValidationEventHandler;
Console.WriteLine("[{1}] Validating {0}", xmlPath, currentItemIndex.ToString());
// setup the XML reader itself
XmlReader xml = XmlReader.Create(xmlPath, config);
try
{
while (!xml.EOF)
{
// go through each XML node
xml.Read();
};
}
catch (Exception e)
{
// and finally report if there's something wrong
Console.WriteLine("!!! " + e.Message);
FileDetails.allFiles[currentItemIndex].errorList.Add(e.Message);
}
现在我在验证DITA文件方面遇到了问题,因为它们带有多个相互引用的DTD / MOD / ENT文件。因此,当我使用上述代码验证示例DITA文件时,我会收到多个错误:
Element 'concept' is not declared.
Element 'title' is not declared.
Element 'conbody' is not declared.
Element 'p' is not declared.
所有DTD文件都是可访问的,所以我认为问题是一次只能处理1个DTD文件,并且无法加载DTD中引用的其他ENT / MOD文件。这是引用外部文件的示例DTD的一部分:
DTD参考
<!ENTITY % ui-d-dec PUBLIC
"-//OASIS//ENTITIES DITA User Interface Domain//EN"
"uiDomain.ent" >
%ui-d-dec;
<!ENTITY % hi-d-dec PUBLIC
"-//OASIS//ENTITIES DITA Highlight Domain//EN"
"highlightDomain.ent" >
%hi-d-dec;
<!ENTITY % pr-d-dec PUBLIC
"-//OASIS//ENTITIES DITA Programming Domain//EN"
"programmingDomain.ent" >
%pr-d-dec;
<!ENTITY % sw-d-dec PUBLIC
"-//OASIS//ENTITIES DITA Software Domain//EN"
"softwareDomain.ent" >
%sw-d-dec;
<!ENTITY % ut-d-dec PUBLIC
"-//OASIS//ENTITIES DITA Utilities Domain//EN"
"utilitiesDomain.ent"
有谁知道如何利用所有这些文件进行验证?