I have a prototype XML schema - see end of post for an extract. What I'd like to do is to make the "row" and "column" attributes optional if there is only 1 "input" element, but required if there are multiple "input" elements. How do I do this in XSD syntax?
我有一个原型XML模式 - 请参阅文章末尾的摘录。我想做的是,如果只有1个“input”元素,则“row”和“column”属性是可选的,但如果有多个“input”元素则需要。我如何在XSD语法中执行此操作?
Also, this schema was generated from a tool, and it seems overly complex. Is there any way I can remove the "xs:extension"/"xs:simpleContent"/"xs:complexType" elements?
此外,此架构是从工具生成的,看起来过于复杂。有什么办法可以删除“xs:extension”/“xs:simpleContent”/“xs:complexType”元素吗?
XML schema extract:
XML模式提取:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" targetNamespace="foobar"
xmlns:f="foobar">
<xs:element name="inspection">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element ref="f:input" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="input">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:integer">
<!--other attributes-->
<xs:attribute name="row" use="optional" type="xs:integer" />
<xs:attribute name="column" use="optional" type="xs:integer" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:schema>
1 个解决方案
#1
0
In XML schema 1.0 what you are suggesting isn't possible.
在XML模式1.0中,您所建议的是不可能的。
Also, with regards to this section:
此外,关于这一部分:
Also, this schema was generated from a tool, and it seems overly complex. Is there any way I can remove the "xs:extension"/"xs:simpleContent"/"xs:complexType" elements?
此外,此架构是从工具生成的,看起来过于复杂。有什么办法可以删除“xs:extension”/“xs:simpleContent”/“xs:complexType”元素吗?
There is no simpler way. Your element is complex, as its based on a simple data type, which has been extended. You can make it simpler by giving the element the xs:integer
type directly, but since the xs:integer
data type doesn't have any attributes, you'd lose the row
and column
attributes.
没有更简单的方法。您的元素很复杂,因为它基于简单的数据类型,已经扩展。您可以通过直接为元素提供xs:integer类型来简化它,但由于xs:integer数据类型没有任何属性,因此您将丢失行和列属性。
#1
0
In XML schema 1.0 what you are suggesting isn't possible.
在XML模式1.0中,您所建议的是不可能的。
Also, with regards to this section:
此外,关于这一部分:
Also, this schema was generated from a tool, and it seems overly complex. Is there any way I can remove the "xs:extension"/"xs:simpleContent"/"xs:complexType" elements?
此外,此架构是从工具生成的,看起来过于复杂。有什么办法可以删除“xs:extension”/“xs:simpleContent”/“xs:complexType”元素吗?
There is no simpler way. Your element is complex, as its based on a simple data type, which has been extended. You can make it simpler by giving the element the xs:integer
type directly, but since the xs:integer
data type doesn't have any attributes, you'd lose the row
and column
attributes.
没有更简单的方法。您的元素很复杂,因为它基于简单的数据类型,已经扩展。您可以通过直接为元素提供xs:integer类型来简化它,但由于xs:integer数据类型没有任何属性,因此您将丢失行和列属性。