一、XML引入Schema约束

### --- xml中引入schema约束的步骤:

~~~ # 查看schema文档,找到根元素,在xml中写出来
<?xml version="1.0" encoding="UTF-8" ?>

<students>
</students>
~~~     # 根元素来自哪个命名空间。使用xmlns指令来声明

<?xml version="1.0" encoding="UTF-8" ?>
<students
xmlns="http://www.yanqi.com/xml"
>

</students>
~~~     # 引入 w3c的标准命名空间, 复制即可

<?xml version="1.0" encoding="UTF-8" ?>
<students
xmlns="http://www.yanqi.com/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

>
</students>
~~~     # 引入的命名空间跟哪个xsd文件对应?
~~~ # 使用schemaLocation来指定:两个取值:第一个为命名空间 第二个为xsd文件的路径

<?xml version="1.0" encoding="UTF-8" ?>
<students
xmlns="http://www.yanqi.com/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.yanqi.com/xml student.xsd"
>
</students>
~~~     # 命名空间

~~~ 指的是一个环境,所用的标签来自于哪个环境定义的。
~~~     # student.xml

<?xml version="1.0" encoding="UTF-8" ?>
<students
xmlns="http://www.yanqi.com/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.yanqi.com/xml student.xsd"
>
<student number="hehe_1234">
<name>张百万</name>
<age>25</age>
<sex>female</sex>
</student>

<student number="hehe_0000">
<name>小斌</name>
<age>20</age>
<sex>male</sex>
</student>
</students>

二、xml语句

<?xml version="1.0" encoding="UTF-8" ?>
<students
xmlns="http://www.yanqi.com/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.yanqi.com/xml student.xsd"
>
<student number="hehe_1234">
<name>张三</name>
<age>200</age>
<sex>male</sex>
</student>

<student number="hehe_4567">
<name>张三</name>
<age>200</age>
<sex>male</sex>
</student>

</students>











Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart

                                                                                                                                                   ——W.S.Landor