xml xsd 和 xsi 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41035128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between xsd and xsi?
提问by Piyush
What exactly is the difference between XML Schema Documentand XML Schema Instance?
XML Schema Document和XML Schema Instance之间到底有什么区别?
xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Please elaborate.
请详细说明。
采纳答案by kjhughes
xsdand xsiSimilarities
xsd和xsi相似之处
- Both are XML namespace prefixes, abbreviations for an XML namespace.
- Both are, as are all namespace prefixes, arbitrarily named; other namespace prefix abbreviations
could equally well be used. However, both prefixes are conventionaland therefore
recommended. (An also-conventional alternative to
xsdisxs.)
- 两者都是XML命名空间前缀,缩写的 XML命名空间。
- 与所有命名空间前缀一样,两者都是任意命名的;其他命名空间前缀缩写同样可以使用。但是,这两个前缀都是常规的,因此建议使用。(另一种传统的替代方法
xsd是xs。)
xsdand xsiDifferences
xsd和xsi差异
- The
xsd(orxs) prefix referring to the Schema Namespace(http://www.w3.org/2001/XMLSchema) is used in XML Schemas (XSDs) for the elements, attributes, and types of the W3C XML Schema Recommendationitself. (This is possible because XML Schema is itself XML.) The
xsiprefix referring to the The Schema Instance Namespacehttp://www.w3.org/2001/XMLSchema-instanceis used in XML document instances for several special attributes defined by the XML Schema Recommendation:xsi:typeallows an XML instance to associate element type information directly rather than through an XSD. See How to restrict the value of an XML element using xsi:type in XSD?xsi:nilallows an empty element to be considered to be valid when the XSD might not otherwise have allowed it.xsi:schemaLocationandxsi:noNamespaceSchemaLocationprovide hints to the XML processor as to how to associate an XSD with an XML document. Usexsi:schemaLocationwhen there is a namespace; usexsi:noNamespaceSchemaLocationwhen there is no namespace.
- 引用架构命名空间( )的
xsd(或xs) 前缀在 XML 架构 (XSD) 中用于W3C XML 架构建议本身的元素、属性和类型。(这是可能的,因为 XML Schema 本身就是 XML。)http://www.w3.org/2001/XMLSchema xsi引用架构实例命名空间的前缀http://www.w3.org/2001/XMLSchema-instance在 XML 文档实例中用于 XML 架构建议定义的几个特殊属性:xsi:type允许 XML 实例直接关联元素类型信息,而不是通过 XSD。请参阅如何在 XSD 中使用 xsi:type 限制 XML 元素的值?xsi:nil当 XSD 可能不允许时,允许将空元素视为有效。xsi:schemaLocation并xsi:noNamespaceSchemaLocation提供提示,以XML处理器为如何将XSD与XML文档相关联。xsi:schemaLocation有命名空间时使用;xsi:noNamespaceSchemaLocation在没有命名空间时使用。
See Also
也可以看看
回答by Sprotty
http://www.w3.org/2001/XMLSchema
http://www.w3.org/2001/XMLSchema
The Simple Version : This is the namespace used within an XML Schema (XSD). An XML schema is used to describe what's valid within an XML instance document.
简单版本:这是在 XML 架构 (XSD) 中使用的命名空间。XML 模式用于描述 XML 实例文档中的有效内容。
The Less Simple Version : This is the namespace of an XML Schema that describes the structure of an XML Schema. In other words a schema that describes itself.
不太简单的版本:这是描述 XML 模式结构的 XML 模式的命名空间。换句话说,一种描述自身的模式。
An XML Schema (XSD) must be written using the types defined within this schema.
XML 模式 (XSD) 必须使用此模式中定义的类型编写。
For Example.
例如。
<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
http://www.w3.org/2001/XMLSchema-instance
This is a namespace used within XML Instance documents to provide additional data to the XML Parser that is processing it. It describes the attributes xsi:schemalocation, xsi:noSchemalocation, xsi:type and xsi:nil which the XML parser can use to assist it with validation.
这是在 XML 实例文档中使用的命名空间,用于向处理它的 XML 解析器提供附加数据。它描述了属性 xsi:schemalocation、xsi:noSchemalocation、xsi:type 和 xsi:nil,XML 解析器可以使用这些属性来帮助它进行验证。
For Example.
例如。
<MyElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="MySchema.xsd">
string
</MyElement>

