SORU
9 Mart 2009, PAZARTESİ


Xml Şema complextype için simpletype veya kısıtlama için öznitelik Ekle

Sorun aşağıdaki gibidir:

Aşağıdaki XML parçacığı var:

<time format="minutes">11:60</time>

Sorun özniteliği ve aynı zamanda kısıtlama hem de ekleyebilirim. Öznitelik biçimi değerler dakika, saat ve saniye alabilir. Zaman restrictionpattern \d{2}:\d{2} vardır

<xs:element name="time" type="timeType"/>
...
<xs:simpleType name="formatType">
<xs:restriction base="xs:string">
    <xs:enumeration value="minutes"/>
    <xs:enumeration value="hours"/>
    <xs:enumeration value="seconds"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="timeType">
    <xs:attribute name="format">
        <xs:simpleType>
            <xs:restriction base="formatType"/>
        </xs:simpleType>
    </xs:attribute>
</xs:complexType>

Eğer timeType karmaşık bir tür yaparsam, bir nitelik, ama kısıtlama yok ekleyebilirim, ve eğer basit bir tip olun, sınırlama ama özniteliği ekleyebilirsiniz. Bu sorunu aşmanın bir yolu var. Bu çok garip bir kısıtlama değil, yoksa değil mi?

CEVAP
9 Mart 2009, PAZARTESİ


Uzantısı oluşturmanız öznitelikleri eklemek için, yüzleri eklemek için kısıtlama ile elde etmek zorundasınız. Bu nedenle bu elemanın alt içerik için iki adımda yapılmalıdır. Özniteliği satır içi tanımlanabilir:

<xsd:simpleType name="timeValueType">
  <xsd:restriction base="xsd:token">
    <xsd:pattern value="\d{2}:\d{2}"/>
  </xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="timeType">
  <xsd:simpleContent>
    <xsd:extension base="timeValueType">
      <xsd:attribute name="format">
        <xsd:simpleType>
          <xsd:restriction base="xsd:token">
            <xsd:enumeration value="seconds"/>
            <xsd:enumeration value="minutes"/>
            <xsd:enumeration value="hours"/>
          </xsd:restriction>
        </xsd:simpleType>
      </xsd:attribute>
    </xsd:extension>
  </xsd:simpleContent>
</xsd:complexType>

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • ChrisCrossMedia

    ChrisCrossMe

    17 EYLÜL 2009
  • SHAYTARDS

    SHAYTARDS

    1 EKİM 2008
  • Tek Syndicate

    Tek Syndicat

    23 Temmuz 2008