天天看點

day07_01_XML學習筆記

day07_01_XML學習筆記

=============================================================================
XML:eXtensible Markup Language 可擴充标記語言 version="1.0"
    特點:可擴充:所有的标簽都是自定義的。  
    功能:資料存儲(HTML:展示資料)
    應用:
        1. 做配置檔案(很常用)。
        2. 做資料傳輸。
--------------------------------------        
    html與xml差別:
        1. html文法松散,xml文法嚴格(區分大小寫等)。
        2. html做頁面展示,xml做資料存儲。
        3. html所有标簽都是預定義的,xml所有标簽都是自定義的。
--------------------------------------    
    W3C:World Wide Web Consortium 網際網路聯盟
-----------------------------------------------------------------------------    
    xml文法:
        文檔聲明:
            必須寫在xml文檔的第一行。
            寫法:<?xml version="1.0" encoding="UTF-8"?>
            屬性:    
                version:版本号,固定值 1.0
                encoding:指定文檔的碼表。預設值為 iso-8859-1
                standalone:指定文檔是否獨立,yes 或 no,一般不用設定
--------------------------------------
        元素:
            就是xml文檔中的标簽。
            文檔中必須有且隻能有一個根元素(根标簽)。
            元素(标簽)需要正确閉合。<body></body>、<br/>
            元素(标簽)需要正确嵌套。
            元素(标簽)名稱要遵守:
                1. 元素名稱區分大小寫(即前後一緻就行)
                2. 數字不能開頭
--------------------------------------        
        文本:
            轉義字元:
                例如:
                    &gt;大于
                    &lt;小于
            CDATA: 當用到轉義字元比較多的時候
                裡邊的資料會原樣顯示
                <![CDATA[ 資料内容 ]]>
                例如:        
                    <![CDATA[
                        if(5>3&&3<6)<abc></abc>
                    ]]>
--------------------------------------                
        屬性:
            屬性值必須用引号引起來。單雙引号都行。
--------------------------------------        
        注釋:
            <!-- -->
--------------------------------------        
        處理指令:現在基本不用,因為xml側重于存儲資料,不側重于顯示資料。
            <?xml-stylesheet type="text/css" href="1.css"?>
-----------------------------------------------------------------------------            
    xml限制:
        限制就是xml的書寫規則。
        限制的分類:
            1. dtd限制:缺點:該限制不嚴謹。
                dtd分類:
                    内部dtd:在xml内部定義dtd。
                    外部dtd:在外部檔案中定義dtd(常用)。
                        引入本地dtd檔案格式:<!DOCTYPE 根标簽 SYSTEM "student.dtd">
                        引入網絡dtd檔案格式:<!DOCTYPE students PUBLIC "名稱空間" "student.dtd">
            2. schema限制:該限制嚴謹。
                導入xsd限制文檔:
                    1、編寫根标簽
                    2、引入執行個體名稱空間 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    3、引入名稱空間 xsi:schemaLocation="http://www.itcast.cn/xml student.xsd"    
                    4、引入預設的名稱空間
                示例:
                <students 
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="http://www.itcast.cn/xml student.xsd"
                    xmlns:="http://www.itcast.cn/xml"
                >
                    <student number="itcast_1001">
                        <name>tom</name>
                        <age>21</age>
                        <sex>male</sex>
                    </student>
--------------------------------------                    
                <students 
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="http://www.itcast.cn/xml student.xsd"
                    xmlns:itcast="http://www.itcast.cn/xml"
                    xmlns:itheima="http://www.itheima.cn/xml"
                >
                    <itcast:student number="itcast_1001">
                        <itcast:name>tom</name>
                        <itcast:age>21</age>
                        <itcast:sex>male</sex>
                    </itcast:student>
                    <itheima:student number="itheima_1001">
                        <itheima:id>001</name>
                        <itheima:email>[email protected]</age>
                    </itheima:student>
=============================================================================          

我的GitHub位址:

https://github.com/heizemingjun

我的部落格園位址:

http://www.cnblogs.com/chenmingjun

我的螞蟻筆記部落格位址:

http://blog.leanote.com/chenmingjun

Copyright ©2018 黑澤明軍

【轉載文章務必保留出處和署名,謝謝!】