gpt4 book ai didi

c# - 级别的 XmlSchema 读取注释

转载 作者:太空宇宙 更新时间:2023-11-03 11:29:12 26 4
gpt4 key购买 nike

我创建了一个模式定义,其开头如下 ...

<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();

但我无法取回我的注释,我错过了什么?

添加:感谢 Morawski 的回复,我最终得到的代码是:

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;
}
}

好吧,我真的认为应该更简单 :)

最佳答案

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)

(注:2004 年;未测试,未确认)

关于c# - <schema> 级别的 XmlSchema 读取注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8400185/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com