先说一下xml和html的区别:XML was designed to describe data and focus on what data is.
HTML was designed to display data and focus on how data looks.
再说一下什么是xml:XML stands for EXtensible Markup Language
XML is a markup language much like HTML
XML was designed to describe data
XML tags are not predefined. You must define your own tags
XML uses a Document Type Definition (DTD) or an XML Schema to describe the data
XML with a DTD or XML Schema is designed to be self-descriptive
拿来主义~~from bbs.xml.org.cn
寫XML文件
<?xml version="1.0"?> 定義標記
<book>
<title>XML</title>
<author>lisongtao</author>
</book>
主要是注意語法的套用
用CSS來顯示XML:
1.XML
--------------------------------------------
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="1.css"?> ''連接CSS樣式表
<lisongtao>
Hello the world!
</lisongtao>
---------------------------------------------
1.CSS
----------------------------------------
lisongtao {display: block; font-size: 48pt; font-weight: bold;}
用XLS來顯示XML:
1.XML
--------------------------------------------
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="2.xsl"?> ''''連接XLS
<lisongtao>
Hello the world!
</lisongtao>
---------------------------------------------
2.xsL
----------------------------------------
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> ''定議模板開始
<xsl:template match="/"> ''根標記
<html>
<head>
<title>hello the world</title>
</head>
<body bgcolor="#CCCCFF">
<h1 align="center"><xsl:value-of select="lisongtao"/></h1>''子節點
</body>
</html>
</xsl:template>
</xsl:stylesheet>
XML 的注釋和JS一樣.
<?xml version="1.0" encoding="gb2312"?>
<!--
这是一些有关书的信息
-->
<books>
<book>
<name>xml应用</name>
<author>list1</author>
<price>55.00</price>
</book>
</books>
gb2312 因该写成 GB2312?????????????
帶屬性的XML節點
<?xml version="1.0"?>
<books title="list">
<book>
<name>xml and asp</name>
<price>45.00</price>
<publisher>tsinghua </publisher>
</book>
</books>
特殊標記的用法:
<?xml version="1.0"?>
<books height="6'5'">
<book width="6"5"">
<name>list &lisongtao</name>
<author>lisongtao < list@263.net></author>
</book>
</books>
XML中的中文標示:
<?xml version="1.0" encoding="gb2312"?>
<好人 >
<name>小鞋子</name>
</好人>
DTD的使用一例
1.DTD
=====================
<?xml version="1.0"?>
<!ELEMENT book (price,name)> 按顺序排列
<!ELEMENT name (#PCDATA)>
<!ELEMENT price (#PCDATA)>
=====================
DTD.XML
==================
<?xml version="1.0"?>
<!DOCTYPE book SYSTEM "1.dtd">
<book> <price>11.2</price>
<name>lisongtao</name>
</book>
把DTD写在XML文件里面
<?xml version="1.0"?>
<!DOCTYPE book [
<!ELEMENT book (price,name)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT price (#PCDATA)>
]>
<book>
<price>11.2</price>
<name>lisongtao</name>
</book>
节点的多属性
<?xml version="1.0" encoding="gb2312"?>
<books>
<book name=" xml应用" author="list1" price="55.00">
</book>
</books>
可缺省的结束标记的方法
<?xml version="1.0" encoding="gb2312"?>
<books>
<book name=" xml应用" author="list1" price="55.00"/>注意这里多了个"/"
</books>
CDATA文件标记的用法一例
<?xml version="1.0" encoding="gb2312"?>
<books>
<![CDATA[
<book>
<name>xml应用</name>
<author>list1</author>
<price>55.00</price>
</book>
]]>
<book>
<name>xml应用</name>
<author>list1</author>
<price>55.00</price>
</book>
</books>
经过以上的学习.总算写出一个标准的XML文件
<?xml version="1.0" encoding="gb2312"?>
<!--这是一个学生选课系统的所有数据-->
<choose_system>
<students>
<student id="984610" lesson_id="11">
<name>栗松涛</name>
<age>25</age>
<sex>男</sex>
<department>自动化</department>
</student>
<student id="984611" lesson_id="12">
<name>李未</name>
<age>26</age>
<sex>男</sex>
<department>自动化</department>
</student>
<student id="984612" lesson_id="11">
<name>张红</name>
<age>23</age>
<sex>男</sex>
<department>自动化</department>
</student>
<student id="984613" lesson_id="12">
<name>李亮</name>
<age>25</age>
<sex>男</sex>
<department>自动化</department>
</student>
</students>
<!-- 本文原载于 http://bbs.xml.org.cn/editannounce.asp?BoardID=1&replyID=1231&id=344&star=1 -->
<lessons>
<lesson id="11">
<name>控制原理</name>
<num>12</num>
<les_start>99.2</les_start>
<les_end>99.7</les_end>
<end_method>考试</end_method>
</lesson>
<lesson id="12">
<name>网络原理</name>
<num>11</num>
<les_start>99.3</les_start>
<les_end>99.6</les_end>
<end_method>通过</end_method>
</lesson>
</lessons>
<teachers>
<teacher id="1122" lesson_id="11">
<name>江华</name>
<age>33</age>
<tea_age>3</tea_age>
<rank>教授</rank>
<publish>控制原理</publish>
<sex>男</sex>
</teacher>
<teacher id="1123" lesson_id="12">
<name>刘佳</name>
<age>40</age>
<tea_age>7</tea_age>
<rank>副教授</rank>
<publish>网络原理</publish>
<sex>男</sex>
</teacher>
</teachers>
</choose_system>
首先作者说了这只是一个"标准的XML文件",它所存放的是"一个学生选课系统的所有数据",当然,可以自己编一个XSLT然后把它显示出来.XML就是用来存储数据的啊!
“IE中无法读入template 不知真么回事”可能是空间申明问题
改为:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
试试看
xml是一个用于不同文件格式转换的工具
具体地讲 就是一个转换工具
让 语言之间 可以相互转换