【发布时间】:2014-08-18 05:03:44
【问题描述】:
这对你们来说可能很简单,但是当使用 c# 针对模式验证 xml 时,我需要能够计算 xml 文档中的属性名称。特别是重复的属性名称(无效)。
如果我的 xsd 里面有这些:
<xsd:schema>
<xsd:complexType name="scheduleEvent">
<xsd:all>
<xsd:element name="Basic" type="MyBasic"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="MyBasic">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="Descriptor" type="Descriptor" maxOccurs="1"/>
<xsd:element name="Descriptor1" type="Descriptor1" maxOccurs="1"/>
</xsd:choice>
</xsd:complexType>
<xsd:complexType name="Descriptor">
<xsd:attribute name="Test" type="typ:Test"/>
</xsd:complexType>
<xsd:complexType name="Descriptor1">
<xsd:attribute name="Test1" type="typ:Test1"/>
</xsd:complexType>
我要验证的 xml 看起来像(无效,我只知道一个快速模拟示例供参考:
声明等...
<ScheduleEvent>
<MyBasic>
<Descriptor Test="02"/>
<Descriptor1 Test1="02" Test1="02"/>
</MyBasic>
</ScheduleEvent>
如何计算“Test1”属性的数量? C# xmlreader(不使用异常,长篇大论)。
【问题讨论】: