一.Schema簡介
Schema是新的XML文檔約束;
Schema本事就是一個XML文檔,但它的擴展名是xsd,而不是XML。
二.名稱空間
名稱空間類似于JAVA中的包,它可以唯一標識一個元素或屬性
(1).指定目標名稱空間
指定當前xsd文件中定義的元素、屬性、類型,都在這個 名稱空間中。
targetNameLocation="http://www.itcast.cn/xml"
(2).在xml中,關聯xsd文件
schemaLocation="目標名稱空間? xsd文件路徑"
<students schemaLocation="http://www.itcast.cn/xml" students.xsd
????????????????????????????????????????????? http://www.edu.cn/xml" edu.xsd>
</students>
ps:可以關聯多個名稱空間
(3).在xml中,指定名稱空間前綴(定義名稱空間)
xml定義名稱空間?? xmlns:"前綴"=“目標名稱空間”
xml定義默認名稱空間? xmlns:="目標名稱空間"
xmlns是特殊的屬性但是schemaLocation不是特殊屬性,它沒有指定前綴,它是W3C提供的。
<students xmlns:it="http://www.itcast.cn/xml"
???????????????xmlns="http://www.edu.cn/xml"
???????????????xmlns:xsi="http://www.w3.org/2001/XML Schema-instance"?
????????xsi: schemaLocation="http://www.itcast.cn/xml student.xsd
??????????????????????????????????????http://www,edu.cn/xml edu.xsd">
?? <it:student>
?????? <name>zhangsan</as:name>
</it:student>
</students>