定义:
noNamespaceSchemaLocation 属性引用一个没有目标命名空间的 XML Schema 文档。
这个属性如何会改变解析的结果?
例如,考虑以下 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>
我从模式中删除了这些命名空间声明:
xmlns:target="http://www.example.com/name"
targetNamespace="http://www.example.com/name"
在引用XML时,即使没有使用noNamespaceSchemaLocation属性,也不会抛出任何错误。我们究竟为什么需要这个属性呢?