自定義xml標簽:
book.xsd
<?xml version="1.0" encoding="UTF-8" ?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.hp.com/bookSchema" elementFormDefault="qualified"> <element name="書架"> <complexType> <sequence maxOccurs="unbounded"> <element name="書"> <complexType> <sequence> <element name="書名" type="string" /> <element name="作者" type="string" /> <element name="售價" type="string" /> </sequence> </complexType> </element> </sequence> </complexType> </element> </schema>
book.xml
<?xml version="1.0" encoding="UTF-8"?> <書架 xmlns="http://www.hp.com/bookSchema" xmlns:dd="http://www.w3.org/2001/XMLSchema-instance" dd:schemaLocation="http://www.hp.com/bookSchema book.xsd"> <書> <書名>JavaScript開發</書名> <作者>老佟</作者> <售價>28.00元</售價> </書> </書架>
幾個重要知識:
相當於schema文件的id
用來指定schema文件的namespace的值
引入一個約束, 它的值是一個schema文件的namespace值
用來指定引入的schema文件的位置
schema規范中: 1. 所有標簽和屬性都需要有schema文件來定義 2. 所有的schema文件都需要有一個id, 但在這里它叫namespace, 3. namespace的值由什么來指定? 由targetNamespace屬性來指定, 它的值是一個url(很有可能不存在) 4. 如何引入一個Schema約束? 屬性? : 用xmlns屬性 屬性值: 對應的schema文件的id(namespace值) 5. 如果引入的schema不是w3c組織定義, 必須指定schema文件的位置 6. schema文件的位置由什么屬性來指定? 屬性? : schemaLocation 屬性值: namespace path 7. 如果引入了N個約束, 需要給n-1個取別名
|