1 / 26

XML 簡介

XML 簡介. Extensible Markup Language 人類、機器皆可讀懂的標籤 XML 的可攜性 跨平台 提供長期 data 保存的格式 理想的檔案交換格式. XML v.s. HTML. XML 有嚴格的語法規定 HTML 因長期使用而存在太多不合規定的語法 < p>(</p>) XML 的標籤表達文件結構及語意 HTML 的標籤表達文件的版面配置 Xml <store></store> Html <td></td>. XML 的組成. 由標籤組成 <?xml version = “1.0”?> <!- - 這裡是註解 - ->

Download Presentation

XML 簡介

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML簡介 • Extensible Markup Language • 人類、機器皆可讀懂的標籤 • XML的可攜性 • 跨平台 • 提供長期data保存的格式 • 理想的檔案交換格式

  2. XML v.s. HTML • XML有嚴格的語法規定 • HTML因長期使用而存在太多不合規定的語法 • <p>(</p>) • XML的標籤表達文件結構及語意 • HTML的標籤表達文件的版面配置 • Xml <store></store> • Html <td></td>

  3. XML的組成 • 由標籤組成 <?xml version = “1.0”?> <!- - 這裡是註解 - -> <message id=“8942020”> <data>Hello! XML!!</data> </message> • 沒有固定的tag和elements • <java></java> • <爪哇></爪哇>

  4. Parsersand Well-Form XML Documents • Parser 是用來解析XML文件的軟體 • Well-formed:滿足XML語法,能順利被parser解讀 • Html存在太多不合規定的寫法,設計瀏覽器的程式設計師必須花很多心力處理這種情況 • <p> • XML文件必須格式正確,Parser才能順利解讀

  5. Well-formed XML • 每個起始標籤一定要有個相對應的結束標籤 • ex: <data></data> • 空元素<br/> <br></br> • 元素不可以重疊 • Ex: <a><b></a></b> • 屬性值必須加引號 • Ex:<person id=“8942020”>purplesea</person> • 元素或屬性裡不能有沒有跳脫的<或&符號 • <SA&D></SA&D>  <SA&amp;D> </SA&amp;D>

  6. XML標籤語法 • <元素> character data </元素> • 大小寫差異性 • 空元素 • Well-formed

  7. XMLTree <person> <name> <first_name>purplesea</first_name> <last_name>Huang</last_name> </name> <profession>programer</profession> </person>

  8. CDATA & 註解 • 之間的東西會被視為字元資料 • <![CDATA &第一行 &第二行 ]]> • 不可在標籤內使用”]]>”字元 因其為結束符號 • 註解寫法: • <!-- 這裡是註解 - -> • 不可用 ---> 當作結束符號

  9. Namespaces EX: <subject>Math</subject> <subject>Thrombosis</subject> • 目的:解決名稱衝突 • 用URI確保相同名稱產生的混淆 <rdf:RDF xmlns:rdf=“http://www.w3.org/TR/REC-rdf-syntax#”> 修改: <rdf:subject ></rdf:subject> <medical:subject></medical:subject>

  10. Document Type Definition(DTD) XML除了well-formed,必須搭配著DTD清 楚定義文件的格式。在資料互相傳送的過 程中,parser可以根據DTD瞭解格式是否 確 。

  11. 如何使用DTD 開始 <! DOCTYPE結尾 > 1.internal subset *在xml裡 <? xml verdion=”1.0” encoding=”Big5” ?> <! DOCTYPE mybook [ <! ELEMENT mybook(#PCDATA)> ]> <mybook>java</mybook>

  12. 2.external subset 將DTD存到一個副檔名為.dtd的存文字檔中 *在 xml 裡 <? xml verdion=”1.0” encoding=”Big5” ?> <! DOCTYPE myMessage SYSTEM “mybook.dtd”> <myMessage> <message>welcome to xml</message> </myMessage> *在mybook.dtd裡  <! ELEMENT myMessage (message)> <! ELEMENT message(#PCDATA)>

  13. 3.同時使用internal and external subset *在 xml 裡 <? xml version=”1.0” encoding=”Big5” ?> <! DOCTYPE books SYSTEM “myMessage.dtd”[ <! Element title (#PCDATA) > ]> …….

  14. Element Type Declarations element之後放的是元素名稱,接著是內容 *在dtd裡 <! ELEMENT book (title,price,author)> <! ELEMENT title (#PCDATA)> <! ELEMENT price (#PCDATA)> <! ELEMENT author (#PCDATA)>

  15. 1.#PCDATA <! ELEMENT title (#PCDATA)> 1.1指的就是Parsable Character Data 是指可以 讓解析器去解讀 1.2如果遇到需要在裡面使用 < > & 需要 跳脫 ,要使用&lt ; &gt ; &amp

  16. 2.子元素 2.1comma( , ) <! ELEMENT book (title,price,author)> 2.2pipe( | ) <! ELEMENT classroom (teacher | student)> 2.3元素出現的數量 ? * + ( + ) 一個到無限多個 <! ELEMENT album (song+)> ( * ) 零個到無限多個 <! ELEMENT library (book*)> ( ? ) 可以有零個或一個 <! ELEMENT seat (person?)>

  17. 2.4mixed *在dtd裡 <! Element myMessage(#PCDATA|message)> <! Element message (#PCDATD)> *在xml裡 <myMessage>Here is some text,some <message>other text</message>and <message>even more text</message>. </myMessage>

  18. 2.5empty *在dtd裡<! Element image Empty> *在xml裡<image></image>或是<image/> 2.6any *在dtd裡<! Element book ANY>

  19. Attribute Declarations *在dtd裡<!ELEMENT X (#PCDATA)> <!ATTLIST X Y CDATA #REQUIRED> 1.CDATA 指的是說可以包含任何一種文字除了(<>& ‘ “) *和XML裡的CDATA些許不同

  20. 2.#REQUIRED是指必須提供一個屬性給x *在dtd裡 <! ELEMENT book (price)> <! ELEMENT price (#PCDATA)> <!ATTLIST price currency CDATA #REQUIRED> *在xml裡 <book> <price currency=“dollar”>java</price> </book>

  21. 3.#IMPLIED是指不一定要提供屬性給ELEMENT 4.#FIXED是指一定要使用原先所提供的值 <! ATTLIST address zip #FIXED “804”>

  22. Attribute Type • ID • IDREF • IDREF的值一定要和ID一樣 • ID的值一定不能是數字 <! ATTLIST shipping shipID ID #REQUIRED > <!ATTLIST book shippedBy IDREF #IMPLIED > < shipping shipID=“suan” > <shipping shipID=“_123456”> 在數字之前加上底線 <book shippedBy=“suan”>

  23. Attribute Type • ENTITY • 先宣告ENTITY的值,然後在attribute後面加上ENTITY替代那個值。 <! ENTITY city SYSTEM “tour.html” NDATA xtml > <! ATTLIST company tour ENTITY #REQUIRD > <company tour=“city”>…</company> O <company tour=“country”>…</company>X

  24. Attribute Type • NMTOKEN(name token) • 允許屬性的值有特殊的符號,例如-- <! ATTLIST sportClub phone NMTOKEN #REQUIRED > < sportsClub phone = “555-111-2002” > • Enumerated Attribute Types 列舉 <! ATTLIST person gender ( M|F ) “F” > <! ATTLIST person gender ( M|F ) #IMPLIED > <! ATTLIST data day ( 1 | 2 | 3 | 4….| 31 ) #REQUIRED>

  25. Conditional Sections • INCLUDE • IGNORE 判斷是要用哪一個element現在是用include的這個 <! [ INCLUDE [ <! ELEMENT message (approved, signature) > ]]> <! [ IGNORE [ <! ELEMENT message (approved,reason, signature) > ]]> <message> <approved flag=“true” /> <signature>Chairman</signature> </message>

  26. Whitespace Characters • Whitespace 處理空白鍵 DTD <! DOCTYPE whitespace [ <! ELEMENT whitespace (hasDATA, hasID, hasNMTOKEN, hasEnumeration, hasMixed )> <! ATTLIST hasCDATA cdata CDATA #REQUIRED > XML <whitespace> <hasCDATA cdata=“ simple cdata “ /> <hasID = “ i20” /> … </whitespace>

More Related