属性 noNamespaceSchemaLocation 对 XML 解析有什么影响? [英] What effect does the attribute noNamespaceSchemaLocation have on XML parsing?

查看:31
本文介绍了属性 noNamespaceSchemaLocation 对 XML 解析有什么影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据定义:

noNamespaceSchemaLocation 属性引用没有目标命名空间的 XML 架构文档.

The noNamespaceSchemaLocation attribute references an XML Schema document that does not have a target namespace.

这个属性将如何改变解析的结果?

How will this attribute ever alter the result of parsing?

以这个 XML 为例:

For example, take this XML:

<?xml version="1.0"?>
<name
  xmlns="http://www.example.com/name"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.example.com/name schema/schema.xsd"
  title="Mr.">
   <first>John</first>
   <middle>M</middle>
   <last>Doe</last>
</name>

引用此架构:

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:target="http://www.example.com/name"
targetNamespace="http://www.example.com/name" elementFormDefault="qualified">
  <element name="name">
    <complexType>
      <sequence>
        <element name="first" type="string"/>
        <element name="middle" type="string"/>
        <element name="last" type="string"/>
      </sequence>
      <attribute name="title" type="string"/>
    </complexType>
  </element>
</schema>

我从架构中删除了这些命名空间声明:

I removed these namespace declarations from the schema:

xmlns:target="http://www.example.com/name" 
targetNamespace="http://www.example.com/name" 

甚至没有在引用 XML 中使用 noNamespaceSchemaLocation 属性,也没有抛出错误.为什么我们甚至首先需要这个属性?

without even using the noNamespaceSchemaLocation attribute in the referencing XML, no error was thrown. Why do we even need this attribute in the first place?

推荐答案

该属性对 XML 解析器没有影响.如果设置了适当的选项,它可能影响 XML 模式处理器的行为;并且它可能类似地影响结合了 XML 解析和 XML 模式验证功能的程序的行为.它告诉模式处理器去哪里寻找描述文档的模式.

The attribute has no effect on an XML parser. It may affect the behaviour of an XML Schema Processor if appropriate options are set; and it may similarly affect the behaviour of a program that combines the functions of XML parsing and XML schema validation. It tells a schema processor where to look for a schema describing the document.

但即使使用模式处理器,noNamespaceSchemaLocation 属性也不会影响像您这样的文档的验证,其中元素都在命名空间中.

But even with a schema processor, the noNamespaceSchemaLocation attribute will not affect the validation of a document like yours where the elements are all in a namespace.

这篇关于属性 noNamespaceSchemaLocation 对 XML 解析有什么影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆