【问题标题】:Where do "name" and "type" attributes come from in xsd:element declarations?xsd:element 声明中的“名称”和“类型”属性从何而来?
【发布时间】:2015-10-17 02:10:10
【问题描述】:

虽然做过XML Schema,但还是有些疑惑:

以下是示例 XML Schema(来自 w3schools):

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://www.w3schools.com"
           xmlns="http://www.w3schools.com"
           elementFormDefault="qualified">

<xs:element name="note">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="to" type="xs:string"/>
      <xs:element name="from" type="xs:string"/>
      <xs:element name="heading" type="xs:string"/>
      <xs:element name="body" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

“名称”和“类型”属性从何而来?在这个 XSD 中,我们定义了可以出现在 XML 文档中的元素。

我们为 XSD 中的大多数元素/构造添加前缀。例如:xs:elementxs:complexType 等。 “名称”和“类型”从何而来?

任何澄清表示赞赏。

【问题讨论】:

  • 架构就是这样定义的。看看this
  • 我要问的是,“name”、“type”是某个命名空间的一部分吗?

标签: xml xsd


【解决方案1】:

XML Schema 中xs:element 声明中的nametype 属性来自W3C XML Schema Recommendation,分别用于定义所声明元素的名称和类型。

它们没有命名空间前缀 (xs:),因为它们没有被定义为在命名空间中。这是设计的。使用xs:namexs:type 会出错。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-22
    • 2011-04-18
    • 2021-12-04
    • 2020-12-16
    • 2020-10-07
    相关资源
    最近更新 更多