Fork me on GitHub

XML Schema choice 元素

XSD :

复制代码
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sch="http://www.ascc.net/xml/schematron" elementFormDefault="qualified">
<xsd:simpleType name="employee">
    <xsd:restriction base="xsd:string">    
    </xsd:restriction>
  </xsd:simpleType>
 <xsd:simpleType name="member">
     <xsd:restriction base="xsd:string">
    </xsd:restriction>
  </xsd:simpleType>
<xsd:element name="person">
  <xsd:complexType>
    <xsd:choice minOccurs="2" maxOccurs="2">
      <xsd:element name="employee" type="employee"/>
      <xsd:element name="member" type="member"/>
    </xsd:choice>
  </xsd:complexType>
</xsd:element>
</xsd:schema>
View Code
复制代码

minOccurs="2" maxOccurs="2" 用于限定 choice里面元素在父元素中出现的次数。

Example:

复制代码
<?xml version="1.0" ?>
<person>
<member></member>
<member></member>
</person>
View Code
复制代码

验证通过。

复制代码
<?xml version="1.0" ?>
<person>
<employee></employee>
<member></member>
</person>
View Code
复制代码

验证通过。

复制代码
<?xml version="1.0" ?>
<person>
<employee></employee>
</person>
View Code
复制代码

验证失败。

 

posted @   HarlanC  阅读(295)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示