What is the difference between xsd and xsi?

What exactly is the difference between an XML Schema Document and an instance of an XML Schema ?

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

Please clarify.

+7
xml xsd
source share
2 answers

xsd and xsi Similarities

  • Both are XML namespace prefixes , abbreviations for XML namespace .
  • Both are, like all namespace prefixes, arbitrarily named; other abbreviations for the namespace prefix could also be used. However, both prefixes are common , and therefore recommended. (An alternative to regular xsd is xs .)

xsd and xsi differences

  • The xsd (or xs ) prefix that references the Schema Namespace ( http://www.w3.org/2001/XMLSchema ) is used in XML Schemas (XSD) for elements, attributes, and types. The W3C XML Schema Recommendation itself. (This is possible because the XML schema itself is XML.)
  • The xsi prefix that refers to the Schema Instance Namespace http://www.w3.org/2001/XMLSchema-instance used in instances of the XML document for certain special attributes according to the XML Schema Recommendation:

    • xsi:type allows an XML instance to directly bind element type information, not via XSD. See How to limit the value of an XML element using xsi: type in XSD?

    • xsi:nil allows you to consider an empty element as valid if XSD cannot otherwise allow it.

    • xsi:schemaLocation and xsi:noNamespaceSchemaLocation provide hints for the XML processor on 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 limit the value of an XML element using xsi: type in XSD?
+6
source share

http://www.w3.org/2001/XMLSchema

Simple Version: This is the namespace used in the XML Schema (XSD). An XML schema is used to describe what is valid in an XML instance document.

A less simple version: this is the XML schema namespace that describes the structure of the XML schema. In other words, a circuit that describes itself.

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

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 the namespace used in XML instance documents to provide additional data to the XML parser that processes it. It describes the xsi: schemalocation, xsi: noSchemalocation, xsi: type, and xsi: no attributes that the XML parser can use to help it validate.

Example.

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

All Articles