从.NET XSD架构文件解压缩枚举值 [英] Extract enumeration values from xsd schema file in .net
本文介绍了从.NET XSD架构文件解压缩枚举值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从XSD架构文件使用.NET编程如何提取元素的枚举约束值?
例如,我想提取从以下XSD奥迪,高尔夫和宝马:
< XS:元素的名称=车>
< XS:简单类型>
< XS:限制基地=XS:字符串>
< XS:枚举值=奥迪/>
< XS:枚举值=高尔夫/>
< XS:枚举值=宝马/>
< / XS:限制>
< / XS:简单类型>
< / XS:组件>
解决方案
有一个的 的XmlSchema
类,但它看起来pretty的......好玩的工作。
请问XML查询就够了吗?
XmlDocument的文档=新的XmlDocument();
doc.Load(Foo.xsd);
XmlNamespaceManager的经理=新的XmlNamespaceManager(doc.NameTable);
mgr.AddNamespace(XX,http://www.w3.org/2001/XMLSchema);
的foreach(的XmlElement EL在doc.SelectNodes(// XX:元素[@名称='车'] [1] / XX:简单类型/ XX:限制/ XX:枚举,经理))
{
Console.WriteLine(el.GetAttribute(价值));
}
How programmatically extract enumeration constraint values of an element from xsd schema file using .net?
for example I'd like to extract 'Audi', 'Golf' and 'BMW' from the following xsd:
<xs:element name="car">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Audi"/>
<xs:enumeration value="Golf"/>
<xs:enumeration value="BMW"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
解决方案
There is an XmlSchema
class, but it looks pretty... "fun" to work with.
Would xml querying be enough?
XmlDocument doc = new XmlDocument();
doc.Load("Foo.xsd");
XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
mgr.AddNamespace("xx", "http://www.w3.org/2001/XMLSchema");
foreach (XmlElement el in doc.SelectNodes("//xx:element[@name='car'][1]/xx:simpleType/xx:restriction/xx:enumeration", mgr))
{
Console.WriteLine(el.GetAttribute("value"));
}
这篇关于从.NET XSD架构文件解压缩枚举值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文