What is the difference between xsd and xsi?

假如想象 提交于 2019-12-04 07:52:27

问题


What exactly is the difference between XML Schema Document and XML Schema Instance ?

  • xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  • xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Please elaborate.


回答1:


xsd and xsi Similarities

  • 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 conventional and therefore recommended. (An also-conventional alternative to xsd is xs.)

xsd and xsi Differences

  • The xsd (or xs) 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 Recommendation itself. (This is possible because XML Schema is itself XML.)
  • The xsi prefix referring to the The Schema Instance Namespace http://www.w3.org/2001/XMLSchema-instance is used in XML document instances for several special attributes defined by the XML Schema Recommendation:

    • xsi:type allows 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:nil allows an empty element to be considered to be valid when the XSD might not otherwise have allowed it.

    • xsi:schemaLocation and xsi:noNamespaceSchemaLocation provide hints to the XML processor as to how to associate an XSD with an XML document. Use xsi:schemaLocation when there is a namespace; use xsi:noNamespaceSchemaLocation when there is no namespace.

See Also

  • Namespace related attributes in XML and XML Schema (XSD)
  • How to restrict the value of an XML element using xsi:type in XSD?



回答2:


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.

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.

An XML Schema (XSD) must be written using the types defined within this schema.

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

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.

For Example.

<MyElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xsi:noNamespaceSchemaLocation="MySchema.xsd">
    string
</MyElement>


来源:https://stackoverflow.com/questions/41035128/what-is-the-difference-between-xsd-and-xsi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!