我有这个 xml 模式
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://hidden/abc" xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://hidden/abc" elementFormDefault="qualified"
attributeFormDefault="unqualified" version="1.8">
<xs:element name="inv_constraint">
<xs:complexType>
<xs:sequence>
---lots of stuff---
</xs:sequence>
<xs:attribute name="unaryOperator">
<xs:annotation>
<xs:documentation>Negate an entire expression.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="not"></xs:enumeration>
<xs:enumeration value="-"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
然后是使用它的 xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<OCL xmlns="http://hidden/abc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://hidden/abc abc.XSD">
------ lots of stuff
<inv_constraint unaryOperator="not">
<property src="A1" ref="PR1"/>
<matOperation operator="ge">
<value>0</value>
</matOperation>
</inv_constraint>
如果我更改 xml 架构以使用带有 ref="" 的属性,如下所示:
...
<xs:attribute ref="unaryOperator"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:attribute name="unaryOperator">
<xs:annotation>
<xs:documentation>Negate an entire expression.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="not"></xs:enumeration>
<xs:enumeration value="-"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
然后我的xml变成:
<inv_constraint xmlns:ns1="http://hidden/abc" ns1:unaryOperator="not">
但我想使用参考
并让我的xml像
<inv_constraint unaryOperator="not">
我该怎么做?
谢谢
在 XML 模式中,所有全局元素、属性或类型定义都必须经过限定。因此,即使您已将 attributeFormDefault 定义为“不合格”,所有全局定义的属性都将以命名空间为前缀。解决方法是在属性组或全局类型内定义此属性,然后您可以引用此命名组或扩展此命名类型。
<xs:attributeGroup name="unaryGroup">
<xs:attribute name="unaryOperator">
<xs:annotation>
<xs:documentation>Negate an entire expression.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="not"></xs:enumeration>
<xs:enumeration value="-"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>
当需要该属性时,请参考attributeGroup而不是attribute。属性组不需要包含元素使用的所有属性,这也应该有效:
<xs:complexType name="UnaryType">
<xs:attributeGroup ref="unaryGroup"/>
<xs:attribute name="otherAttribute" type="xs:string"/>
</xs:complexType>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)