1. 【xml schema】 命名空间解析

先理解几个概念
 
xmlns
xmlns:xsi
xsi:schemaLocation
targetNameSpace
 
1.xmlns 是默认 当没有设置 xmlns:xsi 的时候会使用xmlns 的namespace 否则会使用 xsi 定义好的具体的namespace
xmlns:xsi 定义的namespace 是主要使用的namespace
xsi 可以使用任何单词代替 文档里面叫做perfix
 
2.设置完xmlns:xsi 之后 可以使用下面几个属性
允许一个xml实例直接和element 类型发生联系而不是使用XSD方式
 
2.xsi:nil
允许让一个空element 通过验证 可能XSD不允许空的通过验证
 
3.xsi:schemaLocation 和 xsi:noNamespaceSchemaLocation
用来提供XSD处理 (连接)xml的方式
xsi:schemaLocation 如果有namespace的时候使用
xsi:noNamespaceSchemaLocation 没有namespace的时候使用
xsi:schemaLocation="namespace1 xsd 文件地址"
使用空格隔开 【space-separated pairs of namespace and XSD-location-URI. 】
这个地方还可以定义使用第三方的xsd 文件 【 xml schema document 文件 臆测】
 
如果没有使用到namespace 就必须使用 xsi:noNamespaceSchemaLocation="xsd file uri"
[ whose value is a single XSD-location-URI that hints to the location of the
intended XSD and which should be retrievable]
 
3. targetNamespace 是在xs:schema (XSD 上面的 root element)
【which specifies the namespace of the root element of the XML document instances the XSD is intended to govern.】
用来指定XSD 怎么管理 xml dom 实例中的根元素,必须是默认或者具体的命名空间
 
我们的例子如下
# file.xsd

<xs:schema xmlns="http://www.w3school.com.cn"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3school.com.cn"
elementFormDefault="qualified">

 
# xml
<title 

xmlns="http://www.w3school.com.cn"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3school.com.cn file.xsd">

 
 
 
慢慢沉淀自己
原文地址:https://www.cnblogs.com/martinding/p/7478938.html