xml學習筆記一

XML標准的網址:http:www.w3.org/TR/REC-xml/

現在有XML文件 ,均是由如下模塊組成:
1.元素
2.屬性
3.實體
4.PCDATA(指文本數據)
5.CDATA(指原樣輸出的數據)
DTD文件是,元素聲明使用如下語法:
<!ELEMENT 元素名稱 類別>或者
<!ELEMENT 元素名稱(元素內容)>

例如:
<!ELEMENT 書名 (#PCDATA)>
<!ELEMENT 書籍 (書名,價格,說明)>

空元素的聲明方法如下(用EMPTY關鍵字):
<!ELEMENT 元素名稱 EMPTY>
例如:
DTD中: <!ELEMENT br EMPTY>
XML中: <br/>

表示帶有任何內容的元素(有ANY關鍵字)
例如:
DTD中:<!ELEMENT student ANY>
XML中:
<student>劉偉</student>
<student><name>劉偉</name></student>

DTD中,屬性通過ATTLIST關鍵字來聲明
語法:<!ATTLIST 元素名稱 屬性名稱 屬性類型 默認值>
例子:
DTD中: <!ATTLIST payment type CDATA "cash">
XML中:
<payment type="check"/>
<payment/>


/*************************  參考書籍 ***********************/
Book Name: Beginning XML Databases
Author:  Gavin Powell 
Published Date: © 2007 (490 pages)
ISBN:0471791202
Main Topic : With valuable exercises and step-by-step examples, this  book will help you simplify your database work and provide a more standardized way to exchange data between multiple databases and web sites.
/****************************************************************/


/****================= Chapter 1: What is XML ====================*/

1. XSL:abbreviation for eXtensible Style Sheet
可擴展樣式表語言的縮寫,功能如HTML的CSS樣式表一樣
2. The primary purpose of HTML is for display of data. XML is intended to describe data
HTML用來顯示數據,XML用來描述數據.
3. XML occupies less network bandwidth and involves less processing power
XML與HTML相比占用較少的帶寬和內存
4. XML was built to store and exchange data; HTML is designed to display data
XML是用來存儲和交換數據的,HTML是用來顯示數據的.
5. All XML documents must have a single root node
所有的XML文件有且只有一個根元素.
6. XML Schemas are a more advanced form of the DTD. XML Schemas can be used to define what and how everything is to
be created in an XML document.

7.The XML tag:  The first line in an XML document declares the XML version in use and the encoding  and
if is an isolated document only if in need:
<?xml version="1.0" encoding="UTF-8" standalone="yes/no"?>
Including style sheets:  The optional second line contains a style sheet reference, if a style sheet is in use:
<?xml:stylesheet type="text/xsl" href="cities.xsl"?>

8.XML elements are case sensitive. HTML tags are not case sensitive
XML的標簽和HTML標簽不同,它對大小寫是敏感的.

9.Like HTML tags, XML elements can have attributes. An XML element can have one or more name-value pairs,
and the value must always be quoted. HTML attribute values do not always have to be quoted, although it is advisable.
和HTML一樣,XML元素允許有屬性值.一個XML元素允許有一個或多個的名值對.和HTML不同的是,XML的屬性值必須被指定.

10.Comments:  Both XML and HTML use the same character strings to indicate commented out code:
<!-- This is a comment and will not be processed by the HTML or XML parser -->
XML和HTML的注解方法是一樣的都是用<!-- 這是注解 -->的方式.但是注釋不能出現在第一行的文件聲明之前.

11.Element naming rules:  The names of elements (XML tags) can contain all alphanumeric characters
as long as the name of the element does not begin with a number or a punctuation character.
Also, names cannot contain any spaces. XML delimits between element names and attributes using a space character.
Do not begin an element name with any combination of the letters XML, in any combination of uppercase or lowercase
characters. In other words, XML_1, xml_1, xML_1, and so on, are all not allowed. It will not produce an error to use multiple
operative characters, such as + (addition) and – (subtraction), but their use is inadvisable.
Elements least likely to cause any problems are those containing only letters and numbers. Stay away from odd characters.
元素命名規則:可以包含任何數字或字母,不能用小數點或數字開頭,不允許空格,不允許以XML開頭的字串作為元素名,諸如xml_1,XML_2等,
都是非法的.運算字符最好不要包括在其中(如"+","-"等),雖然語法上是可以的,但不推薦使用.所以最好只用字母或數字來命名元素.
XML用空格區分元素名和它的屬性.


12.Relationships between elements:  The root node has only children.
All other nodes have one parent node, as well as zero or more child nodes.

13.XML namespaces allow for the making of distinctions between different XML documents that have the same elements.
如果在不同XML文件中需要存在多個相同的標簽時,可以會出現沖突,這時可以采用命名空間來區分它們.

14.Different browsers and browser versions will behave differently with XML.
不同的瀏覽器及其版本對XML的解析可能會有差異.

關於數據島(xml data islands)
數據島是一種可以利用<xml>標簽嵌入到html代碼:Beginning XML Databases一文中有提到:
XML documents can also be displayed in a browser using an XML data island. An XML data island is an XML document (with its data) directly or indirectly embedded inside an HTML page. An XML document can be embedded inline inside an HTML page using the HTML <XML> tag. It can also be referenced with an HTML SRC attribute.

實例代碼如下:
<HTML><BODY>
<XML ID="xmlParts">
   <?xml version="1.0"?>
   <parts>
      <part>
         <partnumber>X12334-125</partnumber>
         <description>Oil Filter</description>
         <quantity>$24.99</quantity>
      </part>
      <part>
         <partnumber>X44562-001</partnumber>
         <description>Brake Hose</description>
         <quantity>$22.45</quantity>
      </part>
      <part>
         <partnumber>Y00023-12A</partnumber>
         <description>Transmission</description>
         <quantity>$8000.00</quantity>
      </part>
   </parts>
</XML>
<TABLE DATASRC="#xmlParts">
<TR>
   <TD><DIV  DATAFLD="partnumber"></DIV></TD>   
   <TD><DIV  DATAFLD="$text"></DIV></TD>
</TR>
</TABLE>
</BODY></HTML>


/****========== 2008年11月30日 ==== end of Chapter 1 ====*/

你可能感兴趣的:(html,xml,嵌入式,Exchange,XSL)