Hi!
I must to validate xml document with XmlDSig and Xades Schema.
Why this code (with !obsolete! XmlValidatingReader) work and validate
xmldocument:
private bool schemaValidationStatus = true;
static void ValidationEventHandler(object sender, ValidationEventArgs
e)
{
MessageBox.Show(e.Message);
schemaValidationStatus = false;
}
public bool VerifySchemaVersionObsolete(string fileName)
{
XmlTextReader xmlTextReader = new XmlTextReader(fileName);
XmlValidatingReader xmlValidatingReader = new
XmlValidatingReader(xmlTextReader);
xmlValidatingReader.ValidationType = ValidationType.Schema;
xmlValidatingReader.Schemas.Add("http://www.w3.org/2000/09/
xmldsig#", "http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/
xmldsig-core-schema.xsd");
xmlValidatingReader.Schemas.Add("http://uri.etsi.org/01903/
v1.3.2#", "http://uri.etsi.org/01903/v1.3.2/XAdES.xsd");
xmlValidatingReader.ValidationEventHandler +=
ValidationEventHandler;
while (xmlValidatingReader.Read())
{
}
return schemaValidationStatus;
}
-- and this code (with .net 2.0 without !obsolete!
XmlValidatingReader) DONT WORK:
public bool VerifySchemaNet2(string fileName)
{
XmlTextReader xmlTextReader = new XmlTextReader(fileName);
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
xmlReaderSettings.ProhibitDtd = false;
xmlReaderSettings.ValidationType = ValidationType.Schema;
xmlReaderSettings.Schemas.Add("http://www.w3.org/2000/09/
xmldsig#", "http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/
xmldsig-core-schema.xsd");
xmlReaderSettings.Schemas.Add("http://uri.etsi.org/01903/v1.3.2#",
"http://uri.etsi.org/01903/v1.3.2/XAdES.xsd");
xmlReaderSettings.ValidationEventHandler +=
ValidationEventHandler;
XmlReader xmlReader = XmlReader.Create(xmlTextReader,
xmlReaderSettings);
while (xmlReader.Read())
{
}
return schemaValidationStatus;
}
the error in code VerifySchemaNet2 is in line:
readerSettings.Schemas.Add("http://www.w3.org/2000/09/xmldsig#",
"http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-
schema.xsd");
with message: to use DTD, set false to XmlReaderSettings.ProhibitDtd
and put this to XmlReader.Create method.
How can I validate xml document with
http://www.w3.org/TR/2002/REC-xmldsi...ore-schema.xsd
schema. I dont understand this, other schemas work good. Is imposible
do this with .net 2.0, I dont believe???
Has anybody the same problem?
Please for help!
Iguana