xsd 和 xsi 有什么区别?
What is the difference between xsd and xsi?
XML 架构文档 和XML 架构实例 究竟有什么区别?
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
请详细说明。
http://www.w3.org/2001/XMLSchema
简单版本:这是在 XML 模式 (XSD) 中使用的命名空间。 XML 架构用于描述 XML 实例文档中的有效内容。
不太简单的版本:这是描述 XML 模式结构的 XML 模式的命名空间。换句话说,一个描述自身的模式。
XML 架构 (XSD) 必须使用此架构中定义的类型编写。
例如
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MyElement" type="xs:string" />
</xs:schema>
http://www.w3.org/2001/XMLSchema-instance
这是 XML 实例文档中使用的命名空间,用于向正在处理它的 XML 解析器提供附加数据。它描述了 xsi:schemalocation、xsi:noSchemalocation、xsi:type 和 xsi:nil 属性,XML 解析器可以使用这些属性来帮助它进行验证。
例如
<MyElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="MySchema.xsd">
string
</MyElement>
xsd
和 xsi
相似之处
- 两者都是XML namespace prefixes,一个的缩写
XML namespace.
- 与所有命名空间前缀一样,两者都是任意命名的;其他名称空间前缀缩写
同样可以很好地使用。但是,两个前缀都是 conventional 因此
推荐的。 (
xsd
的另一种常规替代方法是 xs
。)
xsd
和 xsi
差异
xsd
(或xs
)前缀指的是Schema Namespace
(http://www.w3.org/2001/XMLSchema
) 在 XML 模式 (XSDs) 中用于 W3C XML Schema Recommendation 的元素、属性和类型
本身。 (这是可能的,因为 XML 架构本身就是 XML。)
xsi
前缀指的是Schema实例
命名空间http://www.w3.org/2001/XMLSchema-instance
是
在 XML 文档实例中用于定义的几个特殊属性
通过 XML 架构推荐:
xsi:type
allows an XML instance to associate element type information directly rather than through an XSD. See
xsi:nil
允许在 XSD 可能不允许的情况下将空元素视为有效。
xsi:schemaLocation
and xsi:noNamespaceSchemaLocation
向 XML 处理器提供有关如何将 XSD 与 XML 文档相关联的提示。有命名空间时使用xsi:schemaLocation
;当没有命名空间时使用 xsi:noNamespaceSchemaLocation
。
另请参阅
XML 架构文档 和XML 架构实例 究竟有什么区别?
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
请详细说明。
http://www.w3.org/2001/XMLSchema
简单版本:这是在 XML 模式 (XSD) 中使用的命名空间。 XML 架构用于描述 XML 实例文档中的有效内容。
不太简单的版本:这是描述 XML 模式结构的 XML 模式的命名空间。换句话说,一个描述自身的模式。
XML 架构 (XSD) 必须使用此架构中定义的类型编写。
例如
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MyElement" type="xs:string" />
</xs:schema>
http://www.w3.org/2001/XMLSchema-instance
这是 XML 实例文档中使用的命名空间,用于向正在处理它的 XML 解析器提供附加数据。它描述了 xsi:schemalocation、xsi:noSchemalocation、xsi:type 和 xsi:nil 属性,XML 解析器可以使用这些属性来帮助它进行验证。
例如
<MyElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="MySchema.xsd">
string
</MyElement>
xsd
和 xsi
相似之处
- 两者都是XML namespace prefixes,一个的缩写 XML namespace.
- 与所有命名空间前缀一样,两者都是任意命名的;其他名称空间前缀缩写
同样可以很好地使用。但是,两个前缀都是 conventional 因此
推荐的。 (
xsd
的另一种常规替代方法是xs
。)
xsd
和 xsi
差异
xsd
(或xs
)前缀指的是Schema Namespace (http://www.w3.org/2001/XMLSchema
) 在 XML 模式 (XSDs) 中用于 W3C XML Schema Recommendation 的元素、属性和类型 本身。 (这是可能的,因为 XML 架构本身就是 XML。)xsi
前缀指的是Schema实例 命名空间http://www.w3.org/2001/XMLSchema-instance
是 在 XML 文档实例中用于定义的几个特殊属性 通过 XML 架构推荐:xsi:type
allows an XML instance to associate element type information directly rather than through an XSD. Seexsi:nil
允许在 XSD 可能不允许的情况下将空元素视为有效。xsi:schemaLocation
andxsi:noNamespaceSchemaLocation
向 XML 处理器提供有关如何将 XSD 与 XML 文档相关联的提示。有命名空间时使用xsi:schemaLocation
;当没有命名空间时使用xsi:noNamespaceSchemaLocation
。