如何在 XSD 中定义一个简单的元素和属性

How to define a simple element and attribute in XSD

我的 XML 看起来像这样:

<test attri="value">content</test>

我在 XML 架构中构建它时遇到问题,因为我无法提供复杂类型的内容,也无法为简单类型提供属性。我觉得应该有一个我忽略的非常简单的解决方案。

XSD 1.0

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
  <xs:element name="test">
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="xs:string">
          <xs:attribute name="attri" type="xs:string"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
</xs:schema>

使用以下内容:

 <xs:element name="test ">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string">
                    <xs:attribute name="attri" type="xs:string"/>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>