我正在编写一个仪表板设计器,它将根据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”类型.
请参阅下面的示例模式:
使用替代类型,您可以根据属性的值为元素设置不同的类型.在您的情况下,如果@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>