XML 模式:定义类型的类型
我想定义一个包含指定 XML 架构类型的元素的架构。这个问题可能与 XML Schema for schemas 有关问题。
这是我到目前为止所拥有的:
<xs:complexType name="metatype">
<xs:sequence>
<xs:element name="datatype" type="datatype" minOccurs="0" maxOccurs="1"/>
<xs:element name="location" type="locationtype" minOccurs="0"maxOccurs="unbounded"/>
<xs:element name="alias" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="editable" type="xs:boolean" default="false" use="optional"/>
<xs:attribute name="forcedvisible" type="xs:boolean" default="false" use="optional"/>
</xs:complexType>
其中数据类型是:
<xs:complexType name="datatype">
<xs:sequence>
<xs:element name="restriction">
<xs:complexType>
<xs:sequence>
<xs:element name="enumeration">
<xs:complexType>
<xs:attribute name="value" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="base" type="xs:string" use="required"/>
<!-- type xs:string is not accurate for XML Schema type -->
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
我不想在 架构的架构 或至少是 simpleRestrictionType
但我的 XML 架构编辑器(Visual Studio)似乎无法识别这些类型。是否还有其他我需要引用的 XML 架构文档?我真的很想避免定义整个 XML Schema simpleType
元素及其限制子标签等。
I'd like to define a schema that contains elements specifying an XML schema type. This question may be related to the XML Schema for schemas and this question.
Here's what I have so far:
<xs:complexType name="metatype">
<xs:sequence>
<xs:element name="datatype" type="datatype" minOccurs="0" maxOccurs="1"/>
<xs:element name="location" type="locationtype" minOccurs="0"maxOccurs="unbounded"/>
<xs:element name="alias" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="editable" type="xs:boolean" default="false" use="optional"/>
<xs:attribute name="forcedvisible" type="xs:boolean" default="false" use="optional"/>
</xs:complexType>
where datatype is:
<xs:complexType name="datatype">
<xs:sequence>
<xs:element name="restriction">
<xs:complexType>
<xs:sequence>
<xs:element name="enumeration">
<xs:complexType>
<xs:attribute name="value" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="base" type="xs:string" use="required"/>
<!-- type xs:string is not accurate for XML Schema type -->
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
Instead of declaring datatype I'd like to use the localSimpleType
in the Schema for schemas or at least the simpleRestrictionType
but my XML Schema editor (Visual Studio) does not seem to recognize these types. Is there another XML Schema document that I need to reference? I'd really like to avoid defining the whole XML Schema simpleType
element and its subtags for restrictions, etc..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您应该能够编写一个导入 S4S 和其中定义的引用类型的模式。然而,某些工具完全有可能会反对。
您不应该做的一件事是尝试处理修改后的 S4S,或者向 XSD 命名空间添加额外的组件。模式感知工具有权将 S4S 中的所有内容视为公理,向它们提供与这些组件的内置知识不同的定义可能会造成难以估量的破坏。
I think you should be able to write a schema that imports the S4S and references types defined in it. It's entirely possible that some tools will object, however.
One thing you shouldn't do is try to process a modified S4S, or to add extra components into the XSD namespace. Schema-aware tools are entitled to treat everything in the S4S as axiomatic, and presenting them with definitions that differ from their built-in knowledge of these components could cause untold havoc.
您想使用 xsd 还是发明自己的解析器并编写自己的解析器?
您可以定义带有或不带有限制的类型,也可以向已知命名空间(通常包括 xs)中定义的类型添加本地限制。
本地限制最好一次性使用,如果您多次使用它,请为 DRY 定义一种新类型(不要重复自己),
例如
然后
您可以使用它们,就像
调用元素限制一样,不会使其成为一个。 ..
哦,这是我的想法,没有验证它,但它应该很接近。
Do you want to use xsd or invent your own and write your own parser as well?
You can define types with or without restrictions, or you can add a local restriction to a defined type in a known namespace which usually includes xs.
Local restrictions are best for one offs, if you use it more than once, define a new type for DRY (donot repeat yourself)
e.g.
and
Then you can use them as in
calling your element restriction, isn't going to make it one...
Oh off the top of my head this, didn't validate it, but it should be close.