What is the difference between xsd and xsi?
Asked Answered
Q

2

44

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.

Quasimodo answered 8/12, 2016 at 8:43 Comment(1)
What exactly is the difference - well, the exact difference is that they are different schemas that don't have common elements. A helpful link would be w3.org/TR/xmlschema-1/#Instance_Document_Constructions.Platform
D
46

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

See Also

Dunfermline answered 8/12, 2016 at 14:32 Comment(5)
.NET's XmlSerializer seems to introduce these namespace prefixes even though (1) they aren't used in the document it produces, and (2) there is no schema to validate the document it produces. My takeaway is this is all by convention, which I suppose makes some sense, if not a whole lot of sense.Ieyasu
To include unused namespace prefix declarations of any sort is unnecessary but not wrong. Any serializer that includes unused namespace prefix declarations is simply not being as parsimonious as it could be.Dunfermline
Actually, the XmlSerializer uses the XMLSchemaInstance namespace to handle abstract classes, via the xsi:type attribute. It is also possible to generate schemas using XSD.exe. I've never seen the schemas embedded directly in the serialized XML file, but wouldn't surprise me if this was possible too.Expediency
There's a Schema Namespace, there's an Instance Namespace, so what's the use of the Default Namespace?Yeseniayeshiva
@MinhNghĩa: A default namespace is specified on an element via xmlns=" default namespace URI " and places that element and its descendents in the given namespace, by default. A default namespace can be declared in any XML document, including even an XSD, where it can be used to avoid having to specify xsd or xs namespace prefixes on elements throughout the XSD. See also Namespace related attributes in XML and XML Schema (XSD)Dunfermline
C
7

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>
Chishima answered 8/12, 2016 at 11:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.