2010-08-12 7 views
3

i ont ce schéma xmlxml ref attribut de schéma

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

puis ce fichier XML qui l'utilise:

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

si je change le schéma XML pour utiliser l'attribut ref = "" comme ceci:

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

alors mon xml devient:

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

mais je veux utiliser l'arbitre et avoir mon xml comme

<inv_constraint unaryOperator="not"> 

Comment puis-je le faire? merci

Répondre

2

Dans les schémas XML, toutes les définitions d'éléments, d'attributs ou de types globaux doivent être qualifiées. Ainsi, tous les attributs définis globalement seront préfixés par l'espace de noms même si vous avez défini attributeFormDefault comme "non qualifié". Contournement consiste à définir cet attribut dans un groupe d'attributs ou un type global et vous pouvez ensuite faire référence à ce groupe nommé ou étendre ce type nommé.

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

Lorsque vous avez besoin de cet attribut, reportez-vous à attributeGroup au lieu de l'attribut. Le groupe d'attributs n'a pas besoin de contenir tous les attributs que l'élément utilise, cela doit également être valide:

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