Xml schema ref attribute

I have this xml schema

 <?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>

and then this XML file that uses it:

<?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>

if I change the xml schema to use the attribute with ref = "" as follows:

...
<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>

then my xml will be:

<inv_constraint xmlns:ns1="http://hidden/abc" ns1:unaryOperator="not">

but i want to use ref and let my xml like

    <inv_constraint unaryOperator="not">

How can i do this? thank

+3
source share
1 answer

XML- , . , , FormDefault "". , .

<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>

, Group . , , :

<xs:complexType name="UnaryType">
  <xs:attributeGroup ref="unaryGroup"/>
  <xs:attribute name="otherAttribute" type="xs:string"/>
</xs:complexType>
+2

Source: https://habr.com/ru/post/1759374/


All Articles