首页 文章

XML Schema:包含仅包含文本的属性的元素?

提问于
浏览
126

我很难找到这个 . 如何在XML模式文件中为XML定义一个如下所示的元素:

<option value="test">sometext</option>

我无法弄清楚如何定义 xs:string 类型的元素,并且还有一个属性 .

这是我到目前为止所得到的:

<xs:element name="option">
    <xs:complexType>
        <xs:attribute name="value" type="xs:string" />
    </xs:complexType>
</xs:element>

3 回答

  • 70

    尝试

    <xs:element name="option" type="AttrElement" />
    
      <xs:complexType name="AttrElement">
        <xs:simpleContent>
          <xs:extension base="xs:string">
            <xs:attribute name="value" type="xs:string">
            </xs:attribute>
          </xs:extension>
        </xs:simpleContent>
      </xs:complexType>
    
  • -3

    ......或内联等价物:

    <xs:element name="option">
      <xs:complexType>
        <xs:simpleContent>
          <xs:extension base="xs:string">
            <xs:attribute name="value" type="xs:string" />
          </xs:extension>
        </xs:simpleContent>
      </xs:complexType>
    </xs:element>
    
  • 156

    我知道它不一样,但它对我有用:

    <xsd:element name="option">
        <xsd:complexType mixed="true">
            <xsd:attribute name="value" use="optional" type="xsd:string"/>
        </xsd:complexType>
    </xsd:element>
    

相关问题