xsd:any要素を使用しようとすると、スキーマの型に問題があります。検証中に検証例外が発生しました。「MerchantAccount」要素が宣言されていません。
アイデアは、ExtendedProperties要素内の任意のプロパティと値を指定する機能を持つことです。私が間違っていることをアドバイスしてください。
スキーマの一部
...
<xsd:complexType name="ExtendedPropertiesType">
<xsd:sequence>
<xsd:any minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ProcessorInstanceType">
<xsd:all>
<xsd:element name="Id" type="xsd:string" />
<xsd:element name="Descriptor" type="xsd:string" />
<xsd:element minOccurs="0" name="ExtendedProperties" type="ExtendedPropertiesType" />
</xsd:all>
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
...
xmlファイルの一部:
...
<ProcessorInstance name="aaaa">
<Id>37fc527b-2845-43d0-99ca-ac1ff6f0ed86</Id>
<Descriptor>Test</Descriptor>
<ExtendedProperties>
<MerchantAccount>1111</MerchantAccount>
</ExtendedProperties>
</ProcessorInstance>
...
検証コード:
private static XmlDocument loadConfigurationXml(FileInfo configFile)
{
//load schema
var sr = new StringReader(Schemas.ConfigurationSchema);
var schema = XmlSchema.Read(sr, (o, ea) => { throw ea.Exception; });
//validate against the schema
var schemas = new XmlSchemaSet();
schemas.Add(schema);
var readerSettings = new XmlReaderSettings
{
ValidationType = ValidationType.Schema,
ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings,
Schemas = schemas,
};
readerSettings.ValidationEventHandler += (o, ea)=>
{
throw new PaynetValidationException(
string.Format("Invalid configuration file, see schema for details: {0}",
ea.Message),
ea.Exception);
};
var reader = XmlReader.Create(configFile.FullName, readerSettings);
//parse and validate config file
while (reader.Read()){}
var ret = new XmlDocument();
if (configFile.Length != 0)
ret.Load(configFile.FullName);
return ret;
}