我很困惑XmlSchemaException正在向我抛出一个消息。让我提供一些背景。 在我的应用程序中,我使用两种类型的XML参考表:“IFU”和“CC”,都有自己的模式定义。当我加载文件时,我通过使用这些模式来验证它们,并且它的工作完美。直到出现问题。XmlSchemaExeption错误消息
当应用程序被期待IFU REF表(IFU模式选择的)和我加载CC表代替,当检测到错误时,行号拟合(2),但该消息说:
ë .Message =“CCReferenceTable”元素没有声明。“
,而应该说
e.Message = “的 ”IFUReferenceTable“ 元素未声明。”
现在,代码片段:
loadXML的常规
public XmlDocument LoadXML(string filePath, string schemaFilePath)
{
Directory.SetCurrentDirectory(System.IO.Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory));
if (!DoesFileExist(filePath))
throw new Exception(String.Format("File {0} does not exist.", filePath));
if (!DoesFileExist(schemaFilePath))
throw new Exception(String.Format("File {0} does not exist.", schemaFilePath));
XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas.Add(null, schemaFilePath);
settings.ValidationType = ValidationType.Schema;
XmlDocument document = new XmlDocument();
using (XmlReader reader = XmlReader.Create(filePath, settings))
{
document.Load(reader);
}
return document;
}
的XmlSchema
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="IfuReferenceTable">
//////////Other content
</xs:element>
</xs:schema>
XML Refernce表
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IfuReferenceTable>
//////////Other content
</IfuReferenceTable>
CC Ref表看起来与根节点相同(“CCRefenerceTable”而不是“IFUReferenceTable”)。
我错过了什么?
感谢您花时间回答我的问题。那么,现在我觉得很傻 - 这很明显。不过,这有点误导。 – MichalW