XML 模式:为基类型中定义的属性设置固定值

发布于 2024-12-09 07:46:28 字数 2009 浏览 1 评论 0原文

重写基本类型时是否可以将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖树树初阳… 2024-12-16 07:46:28

正如您所说,这可以通过限制来完成,生成的 XSD 看起来像这样

在此处输入图像描述

<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML 2015 Developer Bundle Edition 12.1.2.5004 ([http://www.liquid-technologies.com][2])-->
<xs:schema elementFormDefault="qualified"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType abstract="true"
                    name="Parameter">
        <xs:attribute name="paramterType"
                      type="parameterType" />
    </xs:complexType>
    <xs:simpleType name="parameterType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="singleParameter" />
            <xs:enumeration value="arrayParameter" />
        </xs:restriction>
    </xs:simpleType>
    <xs:complexType name="ParameterImpl1">
        <xs:complexContent>
            <xs:restriction base="Parameter">
                <xs:attribute name="paramterType"
                              fixed="singleParameter"
                              type="parameterType" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="ParameterImpl2">
        <xs:complexContent>
            <xs:restriction base="Parameter">
                <xs:attribute name="paramterType"
                              fixed="arrayParameter"
                              type="parameterType" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
</xs:schema>

As you say this can be accomplished via restriction, the resulting XSD would look something like this

enter image description here

<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML 2015 Developer Bundle Edition 12.1.2.5004 ([http://www.liquid-technologies.com][2])-->
<xs:schema elementFormDefault="qualified"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType abstract="true"
                    name="Parameter">
        <xs:attribute name="paramterType"
                      type="parameterType" />
    </xs:complexType>
    <xs:simpleType name="parameterType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="singleParameter" />
            <xs:enumeration value="arrayParameter" />
        </xs:restriction>
    </xs:simpleType>
    <xs:complexType name="ParameterImpl1">
        <xs:complexContent>
            <xs:restriction base="Parameter">
                <xs:attribute name="paramterType"
                              fixed="singleParameter"
                              type="parameterType" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="ParameterImpl2">
        <xs:complexContent>
            <xs:restriction base="Parameter">
                <xs:attribute name="paramterType"
                              fixed="arrayParameter"
                              type="parameterType" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
</xs:schema>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文