当我们在simpleType中指定name参数时,我们收到一个错误:
"s4s-att-not-allowed: Attribute 'name' cannot appear in element 'simpleType'."
Run Code Online (Sandbox Code Playgroud)
例如:
<xs:simpleType name="lengthValue">
<xs:restriction base="xs:string">
<xs:maxLength value="14"/>
</xs:restriction>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud)
这个例子是正确的吗?为什么我们会收到如上所述的错误?
您的片段可能会也可能不会,具体取决于其上下文.由于您收到了给定的错误,因此您的上下文似乎是一个本地嵌套定义,@name不允许这样做.
xs:simpleType在全局使用时可以给出一个名称.还行吧:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="lengthValue">
<xs:restriction base="xs:string">
<xs:maxLength value="14"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
xs:simpleType在全局使用时可能没有给出名称.这不行:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="e">
<xs:simpleType name="lengthValue">
<xs:restriction base="xs:string">
<xs:maxLength value="14"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
或
lengthValue全局,并使用@type以下方法引用它:下面是如何使用的例子@name有xs:simpleType:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="lengthValue">
<xs:restriction base="xs:string">
<xs:maxLength value="14"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="e" type="lengthValue"/>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)