2012-03-14 12 views
6

Jaki byłby poprawny XML Schema 1.0 Oświadczenie oSchemat XML dla stałego elementu o ustalonym atrybucie?

<notice xml:lang="en">Banana banana banana</notice> 

gdzie:

  1. Atrybut xml: lang jest obowiązkowe
  2. wartość "en" jest stały i obowiązkowy
  3. Treść zawiadomienia jest prostym tekstem.
  4. Treść powiadomienia jest stała (jak wyżej) i obowiązkowa?

Mój najlepszy (ale źle) wysiłek jest następujący fragment:

<xs:element name="notice" use="required" fixed="Banana banana banana"> 
    <xs:complexType> 
    <xs:simpleContent> 
     <xs:extension> 
     <xs:attribute ref="xml:lang" use="required" fixed="en"/> 
     </xs:extension> 
    </xs:simpleContent> 
    </xs:complexType> 
</xs:element> 

Odpowiedz

8
<?xml version="1.0" encoding="utf-8"?> 
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:import namespace="http://www.w3.org/XML/1998/namespace" /> 
    <xs:element name="notice" type="notice"/> 
    <xs:complexType name="notice"> 
     <xs:simpleContent> 
     <xs:extension base="CONTENT"> 
      <xs:attribute ref="xml:lang" use="required" fixed="en"/> 
     </xs:extension> 
     </xs:simpleContent> 
    </xs:complexType> 
    <xs:simpleType name="CONTENT"> 
    <xs:restriction base="xs:string"> 
     <xs:enumeration value="Banana banana banana"/> 
    </xs:restriction> 
    </xs:simpleType> 
</xs:schema> 
+0

Dzięki. Jedyną wadą jest to, że nie wymusza "en" jako xml: lang. Myślę, że można to osiągnąć poprzez dodanie atrybutu fixed = "en" do węzła atrybutu xs: your solution. –

+0

Tak, masz rację! Cieszę się, że to może pomóc. :) –

Powiązane problemy