加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

基于属性值的XML验证(不同的子标签)

发布时间:2020-12-16 07:57:15 所属栏目:百科 来源:网络整理
导读:我正在编写一个仪表板设计器,它将根据xml值创建小部件. 喜欢 dashboard widget type="chart" /widget/dashboard 我想更改 widget中的标签基于@type的值,例如,如果type =“chart”那么它应该允许不同的标签 dashboard widget type="chart" title text="Chart
我正在编写一个仪表板设计器,它将根据xml值创建小部件.

喜欢

<dashboard>
    <widget type="chart">

    </widget>
</dashboard>

我想更改< widget>中的标签基于@type的值,例如,如果type =“chart”那么它应该允许不同的标签

<dashboard>
    <widget type="chart">
        <title text="Chart Title"></title>
        <plotOptions>
            <plotOptions>
                <pie showInLegend="true" shadow="false" innerSize="50%">
                    <dataLabels color="#fff" distance="-20" format="{point.percentage:.0f} %" overflow="false"></dataLabels>
                </pie>
            </plotOptions>
            <legend width="150" align="right" x="10" layout="vertical">
                <navigation></navigation>
            </legend>
            <tooltip enabled="false"></tooltip>
            <exporting enabled="true"></exporting>
        </plotOptions>
    </widget>
</dashboard>

如果我们有type =“table”它应该允许不同的标签

<dashboard>
    <widget type="table">
        <title text="Table Title"></title>
        <thead>
            <tr>
                <th>One</th>
                <th>Two</th>
                <th>Three</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>DS.One</td>
                <td>DS.Two</td>
                <td>DS.Three</td>
            </tr>
        </tbody>
    </widget>
</dashboard>

它还应该在XML编辑器中提供自动建议,如“ECLIPSE”

其他解决方案是使用XML Schema 1.1中的类型替代.
使用替代类型,您可以根据属性的值为元素设置不同的类型.在您的情况下,如果@type的值是“chart”,则可以将widget元素设置为“chart”类型,如果@type的值是“table”,则可以设置为“table”类型.
请参阅下面的示例模式:
<xs:element name="dashboard">
    <xs:complexType>
        <xs:sequence maxOccurs="unbounded">
            <xs:element name="widget" type="widgetBaseType">
                <xs:alternative test="@type='chart'" type="chart"/>
                <xs:alternative test="@type='table'" type="table"/>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:complexType name="widgetBaseType">
    <xs:attribute name="type"/>
</xs:complexType>

<xs:complexType name="chart">
    <xs:complexContent>
        <xs:extension base="widgetBaseType">
            <xs:sequence>
                <xs:element name="title"/>
                <xs:element name="plotOptions"/>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

<xs:complexType name="table">
    <xs:complexContent>
        <xs:extension base="widgetBaseType">
            <xs:sequence>
                <xs:element name="title"/>
                <xs:element name="thead"/>
                <xs:element name="tbody"/>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读