我创建了一个模式定义,如下所示.
<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>然后加载模式并用以下方法编译它:
System.Xml.Schema.XmlSchemaSet set = new System.Xml.Schema.XmlSchemaSet();
set.Add(schema);
set.Compile();但我无法拿回我的注释,我错过了什么?
加法:感谢莫拉夫斯基的回复,我最后得到的代码是:
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;
}
}嗯,我真的认为这应该更简单:)
发布于 2011-12-06 13:04:31
应该注意的是,元素的每个允许子元素组在XmlSchema类中都有一个相应的属性,除了一个元素。这导致一些人认为不能从XmlSchema类获得注释,但事实并非如此。注释可以从XmlSchema类的Items属性中检索。下面的代码示例演示如何在books.xsd架构中打印注释的内容。
System.Xml.Schema名称空间的秘密(在MSDN上)
(注:日期:2004年;未测试,未确认)
https://stackoverflow.com/questions/8400185
复制相似问题