none
Loading Schema from Assembly RRS feed

  • Question

  • Hi all

    Given the XmlReaderSettings below.

    Given that I have all my schemas loaded and complied in a dll file (BizTalk project)

    example MySchemas.dll ( which contains a schema name order.xsd)

    How can I refernce this order.xsd?

    booksSettings.Schemas.Add(http://www.contoso.com/order, "MySchemas.books.xsd"); // this is not working ;-(

    Thanks in Advance

    using System;
    using System.Xml;
    using System.Xml.Schema;
    
    class XmlSchemaSetExample
    {
        static void Main()
        {
            XmlReaderSettings booksSettings = new XmlReaderSettings();
            booksSettings.Schemas.Add("http://www.contoso.com/books", "books.xsd");
            booksSettings.ValidationType = ValidationType.Schema;
            booksSettings.ValidationEventHandler += new ValidationEventHandler(booksSettingsValidationEventHandler);
    
            XmlReader books = XmlReader.Create("books.xml", booksSettings);
    
            while (books.Read()) { }
        }
    
        static void booksSettingsValidationEventHandler(object sender, ValidationEventArgs e)
        {
            if (e.Severity == XmlSeverityType.Warning)
            {
                Console.Write("WARNING: ");
                Console.WriteLine(e.Message);
            }
            else if (e.Severity == XmlSeverityType.Error)
            {
                Console.Write("ERROR: ");
                Console.WriteLine(e.Message);
            }
        }
    }
    


    AKE

    Monday, August 26, 2013 10:05 AM

Answers

  • Just solved it

    I created an instance of the Assembly MySchema.dll

    and then used booksSettings.Schemas.Add(mySchemasInstance.Schema);

    This works.. Any better Idea?


    AKE

    • Marked as answer by Akaschmid Tuesday, August 27, 2013 7:05 AM
    Monday, August 26, 2013 12:24 PM

All replies

  • Just solved it

    I created an instance of the Assembly MySchema.dll

    and then used booksSettings.Schemas.Add(mySchemasInstance.Schema);

    This works.. Any better Idea?


    AKE

    • Marked as answer by Akaschmid Tuesday, August 27, 2013 7:05 AM
    Monday, August 26, 2013 12:24 PM
  • You may want to use a XDocument instead of an XMLDocuments.  The XDocument will allow you to use LINQ where you can use the OrderBy() method.

    jdweng

    Monday, August 26, 2013 1:10 PM