xsd是xml的约束文件。话不多说,直接上例子:
xsd文件头:
<?xml version="1.0"?>
//xmlns:xml命名空间,请忽略括号中的内容
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema(基础xmlns,并使用xs前缀)"
targetNamespace="http://www.w3school.com.cn(为当前xsd命名)"
xmlns="http://www.w3school.com.cn(默认xmlns)"
elementFormDefault="qualified">
...
...
</xs:schema>
1。schema为xsd文件根元素
2。xmlns指xml元素的命名空间。
3。xmlns:xs="http://www.w3.org/2001/XMLSchema"这个片段表明xsd文件的元素与数据类型来自”http://www.w3.org/2001/XMLSchema“这个命名空间,并指出使用这个空间里的元素应该使用xs前缀。这个命名空间是一个基础空间。
4。targetNamespace="http://www.w3school.com.cn"这个片段目的在于为当前xsd文件指定命名空间,其他xml文件应用当前xsd时就可以使用这个命名空间了。
5。xmlns="http://www.w3school.com.cn"表明默认命名空间
6。elementFormDefault="qualified"指出任何 XML 实例文档所使用的且在此 schema 中声明过的元素必须被命名空间限定
xml文件头:
<?xml version="1.0"?>
<?? xmlns="http://www.w3school.com.cn(默认xmlns)"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance(xml实例需要的基础xmlns,使用xsi前缀)"
xsi:schemaLocation="http://www.w3school.com.cn note.xsd(为 命名空间:xsd文件位置 键值对)">
1。xmlns="http://www.w3school.com.cn":默认命名空间
2。xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance”:基础xmlns
3。xsi:schemaLocation="http://www.w3school.com.cn note.xsd“:命名空间:xsd文件位置的键值对,可使用空格或换行符分隔。