"name" 和 "type" 属性在 xsd:element 声明中来自哪里?
Where do "name" and "type" attributes come from in xsd:element declarations?
虽然做了XML Schema,但还是有些疑惑:
下面是示例 XML 架构(来自 w3schools):
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
"name" 和 "type" 属性从何而来?在此 XSD 中,我们定义了可以出现在 XML 文档中的元素。
XSD 中的大多数 elements/constructs 我们都添加了前缀。例如:xs:element
、xs:complexType
等。 "name" 和 "type" 从哪里来?
感谢任何澄清。
XML 架构中 xs:element
声明的 name
和 type
属性来自 W3C XML Schema Recommendation,用于定义名称和类型,分别是被声明的元素。
它们没有命名空间前缀 (xs:
),因为它们未定义在命名空间中。这是设计好的。使用 xs:name
或 xs:type
.
是错误的
虽然做了XML Schema,但还是有些疑惑:
下面是示例 XML 架构(来自 w3schools):
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
"name" 和 "type" 属性从何而来?在此 XSD 中,我们定义了可以出现在 XML 文档中的元素。
XSD 中的大多数 elements/constructs 我们都添加了前缀。例如:xs:element
、xs:complexType
等。 "name" 和 "type" 从哪里来?
感谢任何澄清。
XML 架构中 xs:element
声明的 name
和 type
属性来自 W3C XML Schema Recommendation,用于定义名称和类型,分别是被声明的元素。
它们没有命名空间前缀 (xs:
),因为它们未定义在命名空间中。这是设计好的。使用 xs:name
或 xs:type
.