XML 模式:为基类型中定义的属性设置固定值
重写基本类型时是否可以将 xml 属性的值设置为固定值?
例如,我的基本类型如下所示:
<xs:complexType name="Parameter" abstract="true">
... stuff that all parameters have in common ...
<xs:attribute name="parameterType" type="ax21:parameterType"/>
</xs:complexType>
parameterType 类型是一个具有两个可能值的枚举:
<xs:simpleType name="parameterType">
<xs:restriction base="xs:string">
<xs:enumeration value="singleParameter" />
<xs:enumeration value="arrayParameter" />
</xs:restriction>
</xs:simpleType>
Parameter 类型不应使用,而只能作为两个值的基础扩展它的复杂类型:
<xs:complexType name="ParameterImpl1">
<xs:complexContent>
<xs:extension base="ax21:Parameter">
...stuff specific for this implementation of parameter...
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="ParameterImpl2">
<xs:complexContent>
<xs:extension base="ax21:WS_Parameter">
...stuff specific for this implementation of parameter...
</xs:extension>
</xs:complexContent>
</xs:complexType>
在这些子类型中,我想将 parameterType 属性设置为固定值。 有可能这样做吗?
此外,我想解释一下我的案例的背景 - 因为我认为可能有一个更简单的解决方案来解决我的整个问题:
我正在编写一个 WSDL 文件,Parameter 类型用作操作中的输入参数。它仅用作扩展它的两种类型的接口,但在我的 java 服务器端代码(由 Axis2 生成)中处理 Web 服务请求时,我只得到一个 Parameter 对象,而不能找到任何方法来确定请求中实际传递的两个特定子类型中的哪一个。 (除了手动解析 Parameter 对象的 xmlString,这是我想避免的)
希望我的解释足够精确 - 如果您需要其他信息或不明白我想要什么,请告诉我做。
提前致谢!
更新:
经过对此主题的进一步研究,我认为执行此类操作的唯一方法是使用限制继承和多态性,如本文所述:
http://www.ibm.com/developerworks/library/x-flexschema/
因此,在这种情况下,基类型包含该属性,继承类会“覆盖”它,设置一个固定值。
Is it possible to set an xml attribute's value to a fixed value when overriding a base type?
For example, my base type looks like this:
<xs:complexType name="Parameter" abstract="true">
... stuff that all parameters have in common ...
<xs:attribute name="parameterType" type="ax21:parameterType"/>
</xs:complexType>
The type parameterType is an enumeration with two possible values:
<xs:simpleType name="parameterType">
<xs:restriction base="xs:string">
<xs:enumeration value="singleParameter" />
<xs:enumeration value="arrayParameter" />
</xs:restriction>
</xs:simpleType>
The Parameter type should not be used but only serves as a base for two complex-types extending it:
<xs:complexType name="ParameterImpl1">
<xs:complexContent>
<xs:extension base="ax21:Parameter">
...stuff specific for this implementation of parameter...
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="ParameterImpl2">
<xs:complexContent>
<xs:extension base="ax21:WS_Parameter">
...stuff specific for this implementation of parameter...
</xs:extension>
</xs:complexContent>
</xs:complexType>
And in those subtypes I'd like to set the parameterType attribute to a fixed value.
Is there any possibility to do this?
In addition, I'd like to explain the background in my case - because I think there might be a simpler solution to my whole problem:
I'm writing a WSDL file and the Parameter type is used as an input-parameter in an operation. It is only used as an interface for the two types extending it but when processing the web-service request in my java server-side code(generated by Axis2) I only get an Parameter object and can't find any way to determine which of the two specific subtypes actually was passed in the request.
(Except manually parsing the xmlString of the Parameter object, which I want to avoid)
Hopefully my explanations are precise enough - just tell me if you need additional information or don't understand what I'm trying to do.
Thanks in advance!
Update:
After additional research on this topic I think the only way to do something like this is using Inheritance by Restriction and Polymorphism as described in this article:
http://www.ibm.com/developerworks/library/x-flexschema/
So in that case the base-type contains the attribute and the inheriting classes 'override' it, setting a fixed value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所说,这可以通过限制来完成,生成的 XSD 看起来像这样
As you say this can be accomplished via restriction, the resulting XSD would look something like this