c# と .net 3.5 を使用して、インクルードを持つスキーマに対して xml ドキュメントを検証しようとしています。
スキーマとインクルードは次のとおりです。
Schema1.xsd -> another.xsd を含める
another.xsd -> base.xsd を含める
Schema1.xsd を XmlDocument に追加しようとすると、次のエラーが発生します。
型 'YesNoType' が宣言されていないか、単純型ではありません。
Schema1.xsd スキーマをロードするときに base.xsd ファイルが含まれていないため、このエラーが発生していると思います。
XmlSchemaSet クラスを使用しようとしていて、XmlResolver uri をスキーマの場所に設定しています。
注 : すべてのスキーマは、同じディレクトリ E:\Dev\Main\XmlSchemas の下にあります。
ここにコードがあります
string schemaPath = "E:\\Dev\\Main\\XmlSchemas";
XmlDocument xmlDocSchema = new XmlDocument();
XmlSchemaSet s = new XmlSchemaSet();
XmlUrlResolver resolver = new XmlUrlResolver();
Uri baseUri = new Uri(schemaPath);
resolver.ResolveUri(null, schemaPath);
s.XmlResolver = resolver;
s.Add(null, XmlReader.Create(new System.IO.StreamReader(schemaPath + "\\Schema1.xsd"), new XmlReaderSettings { ValidationType = ValidationType.Schema, XmlResolver = resolver }, new Uri(schemaPath).ToString()));
xmlDocSchema.Schemas.Add(s);
ValidationEventHandler valEventHandler = new ValidationEventHandler
(ValidateNinoDobEvent);
try
{
xmlDocSchema.LoadXml(xml);
xmlDocSchema.Validate(valEventHandler);
}
catch (XmlSchemaValidationException xmlValidationError)
{
// need to interogate the Validation Exception, for possible further
// processing.
string message = xmlValidationError.Message;
return false;
}
ネストされたインクルードを含むスキーマに対して xmldocument を検証することに関して、誰かが私を正しい方向に向けることができますか?