xml - XML 验证器如何知道在哪里可以找到在 xml 文档中声明的模式实例以便解析和使用 xsd?

标签 xml validation xsd schema instance

我不明白 xml 验证器(w3c 所称的“架构感知处理器”)如何知道在 xml 文档中对 xsd 的典型外部引用中的架构实例的位置。

这是一个典型的声明:

<root xmlns="www.example.org"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="www.example.org" "http://example.org/schemas/schema1.xsd">
  <foo>some data</foo>
</root>
  1. 我们将根元素及其所有子元素的默认命名空间声明为“www.example.org”

  2. 我们将名称/前缀“xsi”绑定(bind)到命名空间“http://www.w3.org/2001/XMLSchema-instance”。

  3. 如果我理解正确(显然不是这样!),正是 xsi 命名空间引用的实际资源中的信息允许验证器知道 schemaLocation(在下一行中)是xsi(“http://www.w3.org/2001/XMLSchema-instance”)命名空间本身的合法属性。

但是命名空间不是位置 (URI),那么解析器如何知道去哪里确定 schemaLocation 实际上是否是“http://www.w3.org/2001/XMLSchema-instance”命名空间中定义的属性?

最佳答案

验证器内置了该命名空间的架构。XML 架构定义规范 section 2.7 Schema-Related Markup in Documents Being Validated说:

XML Schema Definition Language: Structures defines several attributes for direct use in any XML documents. These attributes are in the schema instance namespace (http://www.w3.org/2001/XMLSchema-instance) described in The Schema Instance Namespace (xsi) (§1.3.1.2) above. All schema processors must have appropriate attribute declarations for these attributes built in, see Attribute Declaration for the 'type' attribute (§3.2.7.1), Attribute Declaration for the 'nil' attribute (§3.2.7.2), Attribute Declaration for the 'schemaLocation' attribute (§3.2.7.3) and Attribute Declaration for the 'noNamespaceSchemaLocation' attribute (§3.2.7.4).

关于xml - XML 验证器如何知道在哪里可以找到在 xml 文档中声明的模式实例以便解析和使用 xsd?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54383535/

相关文章:

php - 如何从 PHP 中的 XML 文档中检索注释

sql-server - tsql for xml,复杂的 xml

javascript - 处理表单时禁用提交按钮

java - 未调用自定义注释

php - PHP 单元测试中基于 XSD 模式的 XML 验证

c# - 属性 C# 上的几个 XmlElement 属性

java - Android:使用单击按钮在单个相对布局中创建两个线性布局

javascript - V-validate 不适用于插值属性

java - jaxb如何按属性对元素进行排序?

xml - 使用 JAXB 的 bool 属性的 getter