Schema約束自定義xml中的標簽並xml引用的詳解


自定義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元</售價>
    </書>
</書架>

 

 

幾個重要知識:

  1. namespace

相當於schema文件的id

  1. targetNamespace屬性

用來指定schema文件的namespace的值

  1. xmlns屬性

引入一個約束, 它的值是一個schema文件的namespace

  1. schemaLocation屬性

用來指定引入的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個取別名

   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM