2
xsd : any 요소를 사용할 때 내 스키마의 형식에 문제가 있습니다 유효성 검사 중에 유효성 검사 예외가 발생했습니다 : 'MerchantAccount'요소가 선언되지 않았습니다.xsd : any가있는 스키마 - XmlReader 유효성 검사 오류
아이디어는 ExtendedProperties 요소 내에서 모든 속성과 값을 지정할 수있는 능력을 갖는 것입니다. 내가 뭘 잘못하고 있는지 조언 해주세요.
...
<ProcessorInstance name="aaaa">
<Id>37fc527b-2845-43d0-99ca-ac1ff6f0ed86</Id>
<Descriptor>Test</Descriptor>
<ExtendedProperties>
<MerchantAccount>1111</MerchantAccount>
</ExtendedProperties>
</ProcessorInstance>
...
검증 코드 : 스키마 XML 파일의
...
<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>
...
제품의
부
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;
}
답변 해 주셔서 감사합니다. 라고하는 방식으로 정의가 변경되었지만 'MerchantAccount'요소에 대한 스키마 정보를 찾을 수 없습니다. '라는 오류 메시지가 표시됩니다. – IlliakaillI
하지만! processContents = "skip"이 완벽하게 작동합니다. 오류의 원인을 알려 주셔서 감사합니다. 문제가 해결되었습니다! – IlliakaillI
"스키마 정보를 찾을 수 없습니다"라는 경고 또는 오류가 있습니까? 나는 그것이 경고라고 내기. 경고를 원하지 않으면'XmlSchemaValidationFlags.ReportValidationWarnings'을 생략 할 수 있습니다. 경고는 항상 "찾을 수 없습니다". –