[英]XML Schema: using “restriction” vs just using “type” in an element
I'm reviewing an XSD and looking for opportunities to make it less verbose. 我正在审查XSD,并寻找机会使其不再那么冗长。
I ran across lots of instances like this: 我遇到了很多这样的实例:
<xs:element name="MyElement" maxOccurs="1" minOccurs="1" nillable="false">
<xs:annotation>
<xs:documentation>Some documentation</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="MyType"/>
</xs:simpleType>
</xs:element>
Isn't that equivalent to: 那不等于:
<xs:element name="MyElement" type="MyType" maxOccurs="1" minOccurs="1" nillable="false">
<xs:annotation>
<xs:documentation>Some documentation</xs:documentation>
</xs:annotation>
</xs:element>
? ?
If it matters, here's the type: 如果很重要,请输入以下类型:
<xs:simpleType name="MyType">
<xs:restriction base="xs:string">
<xs:maxLength value="100"/>
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
Yes, for all practical purposes (certainly for validation purposes) it's equivalent. 是的,对于所有实际目的(一定是出于验证目的),它是等效的。 There might be data-binding applications that would give different results in the two cases, I wouldn't know.
我不知道,在这两种情况下,可能会有数据绑定应用程序给出不同的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.