Extend XSD Type based on element value?

好久不见. 提交于 2019-11-29 16:52:25

No, an element's type cannot depend upon the value of another element in XSD 1.0 or XSD 1.1.

Alternative Solutions

  1. Redesign your XML. Rather than have a generic Field element with a generic Type child element, include the type in the name of each element:

    <Text>
        <Title>Text Field</Title>
        <Length>100</Length>
    </Text>
    
    <Date>
        <Title>Date Field</Title>
        <Format>mm/dd/yyyy</Format>
    </Date>
    
  2. Change Type from an element to an attribute and use XSD 1.1's Conditional Type Assignment. For an example, see How to make type depend on attribute value using Conditional Type Assignment. (XSD 1.1 only)

  3. Express your constraints via xs:assertion. (XSD 1.1 only)

Alternative #1 is prefered and can be easily implemented in both XSD 1.0 or XSD 1.1. It can also accommodate extension from a common base type.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!