Schema(補充)

一.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>

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容