【发布时间】:2017-06-04 16:03:03
【问题描述】:
我有一个 XML 文档,其中包含一系列重复的地址,其实际内容取决于包含的枚举的值。我想这是一种“标记工会”[或“歧视工会”?]:
{
<AddressList>
<Address>
<AddressType type="addressEnum" fixed="CanadianAddress"/>
<AddressValue>
<Street type="textstring">123 Yonge Street</Street>
<Province type="provinceEnum" value="Ontario"/>
<PostalCode type="postalCodeType" value="M1N 2O3"/>
</AddressValue>
</Address>
<Address>
<AddressType type="addressEnum" fixed="USAddress"/>
<AddressValue>
<Street type="textstring">456 Front Street</Street>
<State type="stateEnum" value="New York"/>
<ZipCode type="zipCodeType" value="12345"/>
</AddressValue>
</Address>
</AddressList>
}
我不清楚如何表达 XML 模式 [即XSD] 用于上述 XML。我是否需要一个空的“AddressType”,“CanadianAddressType”和“USAddressType”都可以扩展?如果我有 50 个地址类型,我需要 50 个这样的扩展吗?
注意:如果不明显,USAddress 的元素不能出现在 CanadianAddress 枚举之后。同样,CanadianAddress 的元素不能出现在 USAdaddress 枚举之后。
【问题讨论】:
标签: xml xsd discriminated-union