问题
My XML looks like this:
<test attri="value">content</test>
I have trouble building this in XML Schema, since I can't give a complexType content and can't give a simpleType an attribute. I feel like there should be a very simple solution to this that I am overlooking.
回答1:
use the following:
<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>
回答2:
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>
来源:https://stackoverflow.com/questions/31271512/how-to-define-a-simple-element-and-attribute-in-xsd