Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot validate against multiple xsd schemas in C#

I wanna verify a digitally signed xml against its schema definition while this schema actually contains this tag

<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd" id="schema"/>

Then I tried to load schemas:

XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas.Add(null, "a.xsd");
settings.Schemas.Compile();

I will get the following error The 'http://www.w3.org/2000/09/xmldsig#:Signature' element is not declared.

like image 412
cui chun Avatar asked Nov 27 '25 21:11

cui chun


2 Answers

You need to also load in the imported schema with another

settings.Schemas.Add([importednamespace], [pathtoimportedXSD]);

The scheme xmldsig-core-schema.xsd does not charge for security reasons since it makes reference to a DTD to validate the upload directory and add it as another scheme.

<!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSchema 200102//EN" "http://www.w3.org/2001/XMLSchema.dtd"

this works The solution is C#

XElement xsdMarkup = XElement.Load("C:\\Proyectos\\WindowService\\Sbif\\Schema\\Schema\\IndicadoresFinancieros-v1.0.xsd");

XElement xsdMarkup2 = XElement.Load("http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd");

XmlSchemaSet schemas = new XmlSchemaSet();

schemas.Add(null, xsdMarkup.CreateReader());
schemas.Add(null, xsdMarkup2.CreateReader());

schemas.Compile();
like image 21
Rodrigo Gomez I. Avatar answered Nov 30 '25 10:11

Rodrigo Gomez I.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!