Java XML架构:为基类型中定义的属性设置固定值
重写基类型时,是否可以将xml属性的值设置为固定值 例如,我的基本类型如下所示:Java XML架构:为基类型中定义的属性设置固定值,java,xml,web-services,wsdl,xsd,Java,Xml,Web Services,Wsdl,Xsd,重写基类型时,是否可以将xml属性的值设置为固定值 例如,我的基本类型如下所示: <xs:complexType name="Parameter" abstract="true"> ... stuff that all parameters have in common ... <xs:attribute name="parameterType" type="ax21:parameterType"/> </xs:complexType> ...
<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>
不应使用参数类型,而应仅作为扩展它的两个复杂类型的基础:
<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文件,参数类型用作操作中的输入参数。它仅用作扩展它的两种类型的接口,但在我的java服务器端代码(由Axis2生成)中处理web服务请求时,我只得到一个参数对象,无法找到任何方法来确定请求中实际传递了两个特定子类型中的哪一个。 (除了手动解析Parameter对象的xmlString,我希望避免这种情况) 希望我的解释足够准确——如果你需要更多信息或者不明白我想做什么,请告诉我 提前谢谢 更新:
在对这一主题进行进一步研究之后,我认为实现这一点的唯一方法是使用本文所述的限制继承和多态性:
因此,在这种情况下,基类型包含属性,继承类“覆盖”它,设置一个固定值。
正如您所说的,这可以通过限制来实现,结果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>
遗憾的是,您的更新链接自2011年以来已断开。网站上有一个存档版本