xsd和xsi有什么区别?

时间:2022-02-16 22:27:16

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

XML Schema Document和XML Schema Instance之间究竟有什么区别?

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

Please elaborate.

请详细说明。

2 个解决方案

#1


9  

xsd and xsi Similarities

  • Both are XML namespace prefixes, abbreviations for an XML namespace.
  • 两者都是XML名称空间前缀,XML名称空间的缩写。
  • 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的常规替代方案是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.)
  • 引用模式命名空间(http://www.w3.org/2001/XMLSchema)的xsd(或xs)前缀在XML模式(XSD)中用于W3C XML模式建议书本身的元素,属性和类型。 (这是可能的,因为XML Schema本身就是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前缀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 How to restrict the value of an XML element using xsi:type in XSD?

      xsi:type允许XML实例直接关联元素类型信息,而不是通过XSD。请参阅如何在XSD中使用xsi:type限制XML元素的值?

    • xsi:nil allows an empty element to be considered to be valid when the XSD might not otherwise have allowed it.

      xsi:nil允许在XSD可能不允许的情况下将空元素视为有效。

    • 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.

      xsi:schemaLocation和xsi:noNamespaceSchemaLocation向XML处理器提供有关如何将XSD与XML文档关联的提示。有命名空间时使用xsi:schemaLocation;没有命名空间时使用xsi:noNamespaceSchemaLocation。

See Also

#2


4  

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 Schema(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 Schema结构的XML Schema的命名空间。换句话说,描述自己的模式。

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 Parser提供其他数据。它描述了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>

#1


9  

xsd and xsi Similarities

  • Both are XML namespace prefixes, abbreviations for an XML namespace.
  • 两者都是XML名称空间前缀,XML名称空间的缩写。
  • 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的常规替代方案是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.)
  • 引用模式命名空间(http://www.w3.org/2001/XMLSchema)的xsd(或xs)前缀在XML模式(XSD)中用于W3C XML模式建议书本身的元素,属性和类型。 (这是可能的,因为XML Schema本身就是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前缀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 How to restrict the value of an XML element using xsi:type in XSD?

      xsi:type允许XML实例直接关联元素类型信息,而不是通过XSD。请参阅如何在XSD中使用xsi:type限制XML元素的值?

    • xsi:nil allows an empty element to be considered to be valid when the XSD might not otherwise have allowed it.

      xsi:nil允许在XSD可能不允许的情况下将空元素视为有效。

    • 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.

      xsi:schemaLocation和xsi:noNamespaceSchemaLocation向XML处理器提供有关如何将XSD与XML文档关联的提示。有命名空间时使用xsi:schemaLocation;没有命名空间时使用xsi:noNamespaceSchemaLocation。

See Also

#2


4  

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 Schema(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 Schema结构的XML Schema的命名空间。换句话说,描述自己的模式。

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 Parser提供其他数据。它描述了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>