2013-05-19 50 views
0

我正在嘗試創建一個非常簡單的元素,但無法按照我在架構中想要的方式來定義它。 (我用的氧氣編輯模式,和我的事實,它試圖定義元素的時候給我的錯誤去)xml架構:如何使用字符串pcdata和一個屬性創建元素

我想創建這樣一個元素:

<sc:col-hd id="1">Col hd name</sc:col-hd> 

但我無法在模式中定義它。我最終什麼事做了兩個@atts創建的元素,像這樣:

<sc:col-hd id="1" col-name="bean"/> 

和該DEF是這樣的:

 <xsd:element name="col-hd" maxOccurs="unbounded"> 

      <xsd:complexType> 
       <xsd:attribute name="id" type="xsd:int"/> 
       <xsd:attribute name="col-name" type="xsd:string"/> 
      </xsd:complexType> 
     </xsd:element>   

,但如果我想將其定義爲第一例如,我該怎麼做? xsd:simpleContent是atts之前的唯一允許元素(根據oXygen),但是,根據錯誤必須有一個指向複雜類型的基礎。

必須像第一個例子中那樣定義元素。第二個折衷方案對我來說確實可行,但它讓我感到困擾,我無法像第一個例子那樣找到一種方法來實現它。

謝謝。

回答

1

xsd:simpleContent可以擴展簡單類型,下面應該做你需要的東西:

<xsd:element name="col-hd" maxOccurs="unbounded"> 

     <xsd:complexType> 
      <xsd:simpleContent> 
       <xsd:extension base="xsd:string"> 
        <xsd:attribute name="id" type="xsd:int"/> 
       </xsd:extension> 
      </xsd:simpleContent> 
     </xsd:complexType> 
    </xsd:element>   
相關問題