Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

C# - XSD validation with has imports.

$
0
0

Hello,

I'm kind of new in this about XML and validation. I've got to validate lots of XML with their XSD. I use a sample from MSDN like this:

            XmlReaderSettings booksSettings = new XmlReaderSettings();

            booksSettings.ValidationType = ValidationType.Schema;
            booksSettings.Schemas.Add(null, @"C:\myfile.xsd");
            booksSettings.ValidationEventHandler += new ValidationEventHandler(booksSettingsValidationEventHandler);

            XmlReader books = XmlReader.Create(@"C:\myfile.xml", booksSettings);

            while (books.Read()) { }
            Console.WriteLine("Fin");
            Console.ReadLine();

But, the validation doesn't work because when I change or delete any tag, the validation doesn't show any errors. I thought is because myfile.xsd has an import to this:

<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
    elementFormDefault="qualified"><xs:import namespace="http://www.w3.org/2000/09/xmldsig#"
        schemaLocation="xmldsig-core-schema.xsd"/>

and has this attribute in Signature element.

<xs:element ref="ds:Signature" minOccurs="0">

I've read some posts, I've tried almost all the solutions but I can't get the validation OK. I mean, the code works but when the xsd has an imports, it doesn't work anymore. I've downloaded the xmldsig-core-schema.xsd and tried manually add to the settings.schema but it didn't work.

Any suggestion is welcome.

Best regards.

Sorry, but my english is not my first language.




Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>