XmlSchema reading annotation at <schema> level

I've created a schema definition that starts like this ...

<xs:schema attributeFormDefault="unqualified"  elementFormDefault="qualified" targetNamespace="urn:my.namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:it="urn:mynamespace">
  <xs:annotation>
    <xs:appinfo>My annotation</xs:appinfo>
  </xs:annotation>

      

Then I download the schema and compile it with

System.Xml.Schema.XmlSchemaSet set = new System.Xml.Schema.XmlSchemaSet();
                                    set.Add(schema);
                                    set.Compile();

      

but I am having trouble getting my annotation back, what am I missing?

Addendum: Thanked Moravsky for the answer, the code I ended up with:

string appInfoValue = string.Empty;
                                    var annotation = schema.Items.OfType<XmlSchemaAnnotation>().FirstOrDefault();
                                    if (null != annotation)
                                    {
                                        var appInfo = annotation.Items.OfType<XmlSchemaAppInfo>().FirstOrDefault();
                                        if (null != appInfo)
                                        {
                                            appInfoValue = appInfo.Markup[0].InnerText;
                                        }
                                    }

      

Well, I really assumed it should be easier :)

+2


source to share


1 answer


Note that each of the groups of valid child element elements has a corresponding property in the XmlSchema class, with the exception of one element. This has led some to believe that you cannot get annotations from the XmlSchema class, which is not the case. The annotations can be obtained from the Items property of the XmlSchema class. The following code example demonstrates how to print the content of an annotation in the books.xsd schema.

System.Xml.Schema Namespace Secrets (on MSDN)



(Note: dated 2004, not verified, not verified)

+1


source







All Articles