XML文件:
<root>
<date><![CDATA[<img border=0 src='images/w3china_logo.gif'>]]</date>
</root>XSLT文件:
<xsl:value-of select="root/date" >
发现这样输入显示的是<img border=0 src='images/w3china_logo.gif'>,但我实际要显示的图片。在网上找了一下问题解决,分享一下希望以后不懂的碰到了就可以用上。
只要将XSLT文件改成这样就可以了:
<xsl:value-of select="remark" disable-output-escaping="yes"/>- 添加新评论
- 阅读次数:
| 级别: 中级 |
高级技术架构师, Blast Radius
2005 年 6 月 16 日
文档对象模型(Document Object Model,DOM)是用于操纵 XML 和 HTML 数据的最常用工具之一,然而它的潜力却很少被充分挖掘出来。通过利用 DOM 的优势,并使它更加易用,您将获得一款应用于 XML 应用程序(包括动态 Web 应用程序)的强大工具。
本期文章介绍了一位客串的专栏作家,同时也是我的朋友和同事 Dethe Elza。Dethe 在利用 XML 进行 Web 应用程序开发方面经验丰富,在此,我要感谢他对我在介绍使用 DOM 和 ECMAScript 进行 XML 编程这一方面的帮助。请密切关注本专栏,以了解 Dethe 的更多专栏文章。 —— David Mertz
DOM 是处理 XML 和 HTML 的标准 API 之一。由于它占用内存大、速度慢,并且冗长,所以经常受到人们的指责。尽管如此,对于很多应用程序来说,它仍然是最佳选择,而且比 XML 的另一个主要 API —— SAX 无疑要简单得多。DOM 正逐渐出现在一些工具中,比如 Web 浏览器、SVG 浏览器、OpenOffice,等等。
- 添加新评论
- 阅读次数:
RSS是 Really Simple Syndication的缩写(对rss2.0而言,是这三个词的缩写,对rss1.0而言则是RDF Site Summary的缩写,1.0与2.0走的是两个体系)
RSS 基于XML,所有的 RSS 必须遵循w3c网站上公布的XML 1.0 规范。
在一个RSS文档中,根元素是<rss>,带有一个必备属性version,用以指明该文档遵循的rss规范,如果rss文档遵循本规范,则version值必须是2.0。
<rss>元素只有一个子元素,包含关于频道的一些信息。频道(channel)是整个blog,项(item)指一篇文章或日志(也有称这为post)。
RSS2.0元素channel的子元素列表
| 元素(Element) | 描述(Description) | 值域 | 重要性 | 举例(Example) |
| title | 频道名称 | 必备 | GoUpstate.com News Headlines | |
| link | 频道的URL | 必备 | http://www.goupstate.com/ | |
| Description | 频道的描述 | 必备 | The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site. | |
| language | 频道文章所用语言, | 可用netscape或w3c推荐的列表 | 可选 | en-us |
| copyright | 频道内容的版权说明 | 可选 | Copyright 2002, Spartanburg Herald-Journal | |
| managingEditor | 责任编辑的email | 可选 | geo@herald.com (George Matesky) | |
| webMaster | 负责频道技术事务的网站管理员email | 可选 | betty@herald.com (Betty Guernsey) | |
| pubDate | 频道内容发布日期,格式遵循RFC822格式(年份可为2们或4位) | 可选 | Sat, 07 Sep 2002 00:00:01 GMT | |
| lastBuildDate | 频道内容最后的修改日期 | 可选 | Sat, 07 Sep 2002 09:42:31 GMT | |
| category | 指定频道所属的一个或几个类别 | 可选 | <category>Newspapers</category> | |
| generator | 生成该频道的程序名 | 可选 | MightyInHouse Content System v2.3 | |
| docs | 指向该RSS文件所用格式说明的URL | 可选 | http://blogs.law.harvard.edu/tech/rss | |
| cloud | Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds. More info here. | 可选 | <cloud domain="rpc.sys.com" port="80" path="/RPC2" registerProcedure="pingMe" protocol="soap"/> | |
| ttl | 有效期,用以指明该频道可被缓存的最长时间 | 分钟为单位 | 可选 | <ttl>60</ttl> |
| image | 指定一个 GIF或JPEG或PNG图片,用以与频道一起显示 | 可选 | ||
| rating | 这个频道的分级(主要指成人、限制、儿童等) | 可选 | ||
| textInput | 指定一个text输入框供用户输入,具体信息及功能未定。 | 可选 | ||
| skipHours | 提示新闻聚合器,那些小时时段它可以跳过。 | 可选 | ||
| skipDays | 提示新闻聚合器,那些天它可以跳过。 | 可选 |
RSS2.0元素channel的子元素image的子元素列表
| 元素(Element) | 描述(Description) | 值域 | 重要性 | 举例(Example) |
| url | 图片的url | 必备 | ||
| title | 图片的标题,用于http的alt属性 | 必备 | ||
| link | 网站的url(实际中常以频道的url代替) | 必备 | ||
| width | 图片的宽度(象素为单位) | 最大144,默认88 | 可选 | |
| height | 图片的高度(象素为单位) | 最大400,默认31 | 可选 | |
| description | 用于link的title属性 | 可选 |
RSS2.0元素channel的子元素cloud的子元素列表
| 元素(Element) | 描述(Description) | 值域 | 重要性 | 举例(Example) |
| domain | Cloud程序所在机器的域名或IP地址 | radio.xmlstoragesystem.com | ||
| port | 访问clound程序所通过的端口 | 80 | ||
| path | 程序所在路径(不一定是真实路径) | /RPC2 | ||
| registerProcedure | 注册的可提供的服务或过程 | xmlStorageSystem.rssPleaseNotify | ||
| protocol | 协议 | xml-rpc, soap , http-post 之一 | xml-rpc |
RSS2.0元素channel的子元素textInput的子元素列表
| 元素(Element) | 描述(Description) | 值域 | 重要性 | 举例(Example) |
| title | Submit按钮的标签 | 必备 | ||
| description | 解释text输入区 | 必备 | ||
| name | Text area对象的名字 | 必备 | ||
| link | 处理提交的请求的cgi程序 | 必备 |
- 添加新评论
- 阅读次数:
1. 什么是XSLT
大家可能听说过XSL(eXtensible Stylesheet Language),XSL和我们这里说的XSLT从狭义上理解是一样的,而按照W3C的标准,XSLT的说法更严格些,因此我们在文章中统一使用XSLT的称法。XSLT的英文标准名称为eXtensible Stylesheet Language Transformation。根据W3C的规范说明书(http://www.w3.org/TR/xslt),最早设计XSLT的用意是帮助XML文档(document)转换为其它文档。但是随着发展,XSLT已不仅仅用于将XML转换为HTML或其它文本格式,更全面的定义应该是: XSLT是一种用来转换XML文档结构的语言。
2. 为什么要用XSLT
我们已经知道,XML是一种电脑程序间交换原始数据的简单而标准的方法。它的成功并不在于它容易被人们书写和阅读,更重要的是,它从根本上解决了应用系统间的信息交换。因为XML满足了两个基本的需求:
(1).将数据和表达形式分离。就象天气预报的信息可以显示在不同的设备上,电视,手机或者其它。
(2).在不同的应用之间传输数据。电子商务数据交换的与日俱增使得这种需求越来越紧迫。
为了使数据便于人们的阅读理解,我们需要将信息显示出来或者打印出来,例如将数据变成一个HTML文件,一个PDF文件,甚至是一段声音;同样,为了使数据适合不同的应用程序,我们必须有能够将一种数据格式转换为另一种数据格式,比如需求格式可能是一个文本文件,一个SQL语句,一个HTTP信息,一定顺序的数据调用等。而XSLT就是我们用来实现这种转换功能的语言。将XML转换为HTML,是目前XSLT最主要的功能。
3. XSLT的历史
想很多其他XML家族成员一样,XSLT是由W3C起草和制定的。它的主要发展历程如下:
.1995年由James Clark提议;
.1997年8月正式提案为XSL;
.1998年5月由Norman Walsh完成需求概要;
.1998年8月18日XSL草案发布;
.1999年11月16日正式发布XSL 1.0推荐版本。
目前,XSLT仍然在快速的发展中,XSLT1.1的草案已经可以在W3C网站(http://www.w3.org/TR/xslt11)上看到。
4. 什么是XPath
XPath是XSLT的重要组成部分,我们将在第四章讲解它的详细语法。那么XPath是什么呢?我们首先来了解一下XSL系列的"家族"关系。
XSL在转换XML文档时分为明显的两个过程,第一转换文档结构;其次将文档格式化输出。这两步可以分离开来并单独处理,因此XSL在发展过程中逐渐分裂为XSLT(结构转换)和XSL-FO(formatting objects)(格式化输出)两种分支语言,其中XSL-FO的作用就类似CSS在HTML中的作用。而我们这里重点讨论的是第一步的转换过程,也就是XSLT。
另外,在学习XML时我们已经知道XML是一个完整的树结构文档。在转换XML文档时可能需要处理其中的一部分(节点)数据,那么如何查找和定位XML文档中的信息呢,XPath就是一种专门用来在XML文档中查找信息的语言。XPath隶属XSLT,因此我们通常会将XSLT语法和XPath语法混在一起说。
用一种比较好理解的解释:如果将XML文档看作一个数据库,XPath就是SQL查询语言;如果将XML文档看成DOS目录结构,XPath就是cd,dir等目录操作命令的集合。
5. XSLT和CSS的比较
CSS同样可以格式化XML文档,那么有了CSS为什么还需要XSLT呢?因为CSS虽然能够很好的控制输出的样式,比如色彩,字体,大小等,但是它有严重的局限性,就是:
(1) CSS不能重新排序文档中的元素;
(2) CSS不能判断和控制哪个元素被显示,哪个不被显示;
(3) CSS不能统计计算元素中的数据;
换句话说,CSS只适合用于输出比较固定的最终文档。CSS的优点是简洁,消耗系统资源少;而XSLT虽然功能强大,但因为要重新索引XML结构树,所以消耗内存比较多。
因此,我们常常将它们结合起来使用,比如在服务器端用XSLT处理文档,在客户端用CSS来控制显示。可以减少响应时间。
6. XSLT和IE5
在XSLT草案发布不久,微软就在IE4中提供了支持XSL功能的预览版本,到IE5.0发布时,正式全面支持XSLT,可是由于IE5发布的比XSLT1.0标准时间早,因此在IE5.0中支持的XSTL功能和XSLT 1.0略有不同。(呵呵~~XML推行的主要原因之一就是解决HTML过分依赖浏览器的问题,现在微软又想标新立异?)。好在微软的IE5.5中执行的标准已经和W3C的XSLT1.0基本相近。但令人头疼的是IE5.0已经发行了几百万套,您使用的XSLT很可能不能被客户的浏览器正确执行。目前XSLT 1.1仍在发展中,W3C及有关组织也在和微软协商争取获得统一。呵呵~~故事还远远没有结束噢。
注意:本文中提到的语法都是根据XSLT 1.0的标准来讲的,没有任何微软的"方言"。
- 添加新评论
- 阅读次数:
将一台联网设备中的信息直接共享给另一台设备根本不是一个新想法。毕竟,象 LapLink 这样的远程访问软件,已经问世了近 20 年,可以从远程计算机移动文件和文件夹,传送应用程序设置和目录以及更新已在另一台 PC 上存储的文件。
然而,当今的对等通信需要另外一个高级的层次。象 LapLink 这样的程序主要是设计用来把文件级信息从一台 PC 推到另一台,而 P2P 平台的目标则更进一步:共享数据并链接可能不兼容的应用程序。
- 添加新评论
- 阅读次数:
关键词XML,Client/Server模型 三层结构模型
1.问题的提出
- 添加新评论
- 阅读次数:
1、简介
XMLDOM被设计为可用于任何语言和任何操作系统。借助DOM,程序员可以创建XML文档、遍历其结构,增、改、删其元素。DOM将整个XML文档视作一棵树,文档级的元素是树的根。
2、MS的XML解析,IE5.0以上。
是一个COM组件,至少包含下列对象:
(1)Micosoft.XMLDOM
(2)Micosoft.XMLDOM.parseError,有如下属性:
| Property | Description |
| errorCode | Returns a long integer error code |
| reason | Returns a string explaining the reason for the error |
| line | Returns a long integer representing the line number for the error |
| linePos | Returns a long integer representing the line position for the error |
| srcText | Returns a string containing the line that caused the error |
| url | Returns the url pointing the loaded document |
| filePos | Returns a long integer file position of the error |
(3)Microsoft.XMLHTTP,有如下属性:
| Property | Description |
| readyState | Returns the state of the document |
| responseBody | Returns the response as an array of unsigned bytes |
| responseStream | Returns the response as an IStream |
| responseText | Returns the response as a string |
| responseXML | Returns the response as an xml document |
| status | Returns the status code as a number |
| statusText | Returns the status as a string |
| Property | Description |
| abort() | Cancel the current http request |
| getAllResponseHeaders() | Returns the value of the http headers |
| getResponseHeader(headerName) | Returns the value of one specified http header |
| open(method, url, async, userid, password) | Opens http request, and specifies the information |
| send() | Send the http request to the server |
| setRequestHeader(headerName,headerValue) | Specifies the name of a http header |
(4)Node的类型
| nodeType | Named Constant | nodeTypeString | nodeName | nodeValue |
|---|---|---|---|---|
| 1 | ELEMENT_NODE | element | tagName | null |
| 2 | ATTRIBUTE_NODE | attribute | name | value |
| 3 | TEXT_NODE | text | #text | content of node |
| 4 | CDATA_SECTION_NODE | cdatasection | #cdata-section | content of node |
| 5 | ENTITY_REFERENCE_NODE | entityreference | entity reference name | null |
| 6 | ENTITY_NODE | entity | entity name | null |
| 7 | PROCESSING_INSTRUCTION_NODE | processinginstruction | target | content of node |
| 8 | COMMENT_NODE | comment | #comment | comment text |
| 9 | DOCUMENT_NODE | document | #document | null |
| 10 | DOCUMENT_TYPE_NODE | documenttype | doctype name | null |
| 11 | DOCUMENT_FRAGMENT_NODE | documentfragment | #document fragment | null |
| 12 | NOTATION_NODE | notation | notation name | null |
W3C规定的属性:
| Property | Description |
|---|---|
| attributes | Returns a NamedNodeMap containing all attributes for this node |
| childNodes | Returns a NodeList containing all the child nodes for this node |
| firstChild | Returns the first child node for this node |
| lastChild | Returns the last child node for this node |
| nextSibling | Returns the next sibling node. Two nodes are siblings if they have the same parent node |
| nodeName | Returns the nodeName, depending on the type |
| nodeType | Returns the nodeType as a number |
| nodeValue | Returns, or sets, the value of this node, depending on the type |
| ownerDocument | Returns the root node of the document |
| parentNode | Returns the parent node for this node |
| previousSibling | Returns the previous sibling node. Two nodes are siblings if they have the same parent node |
W3C规定的方法:
| Method | Description |
|---|---|
| appendChild(newChild) | Appends the node newChild at the end of the child nodes for this node |
| cloneNode(boolean) | Returns an exact clone of this node. If the boolean value is set to true, the cloned node contains all the child nodes as well |
| hasChildNodes() | Returns true if this node has any child nodes |
| insertBefore(newNode,refNode) | Inserts a new node, newNode, before the existing node, refNode |
| removeChild(nodeName) | Removes the specified node, nodeName |
| replaceChild(newNode,oldNode) | Replaces the oldNode, with the newNode |
(5)NodeList的W3C规定的属性和方法。
| Property | Description |
|---|---|
| length | Returns the number of nodes in a nodeList |
| Method | Description |
|---|---|
| item | Returns a specific node in the nodeList |
- 添加新评论
- 阅读次数:





