Reputation: 33272
I've created a schema definition that starts like the following ...
<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 load the schema and I compile it with:
System.Xml.Schema.XmlSchemaSet set = new System.Xml.Schema.XmlSchemaSet();
set.Add(schema);
set.Compile();
but I can't manage to get back my annotation, what am I missing ?
Addition: Thankd to Morawski reply, the code I ended up is:
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 suppossed that should be simpler :)
Upvotes: 5
Views: 2697
Reputation: 8404
It should be noted each of the groups of allowed child elements of the element has a corresponding property in the XmlSchema class except one, elements. This has led some to believe that one cannot obtain annotations from the XmlSchema class, which is not the case. Annotations can be retrieved from the Items property of the XmlSchema class. The following code sample shows how to print the contents of the annotation in the books.xsd schema.
Secrets of the System.Xml.Schema Namespace (on MSDN)
(Note: dated 2004; not tested, not confirmed)
Upvotes: 4