msdn关于xml element
w3schools中关于xml island
但对于不规则的xml文件,我死活找不到使用数据岛的方法。好像xml island把xml当成一个类似数据库的表,直接把根目录下的元素当成recordset。所以对于xml文件如下找不到解决的办法:
<?
xml version="1.0" encoding="gb2312"
?>
<!--
file name = rss_down_s10.xml
-->
<
rss
version
="2.0"
>
<
channel
>
<
title
>
123 - 旅游杂志
</
title
>
<
link
>
http://www.china-data.com.cn
</
link
>
<
item
>
<
title
>
[旅游杂志]杭州西湖
</
title
>
<
link
>
http://www.china-data.com.cn/downinfo/93.html
</
link
>
</
item
>
<
item
>
<
title
>
[旅游杂志]桂林旅游
</
title
>
<
link
>
http://www.china-data.com.cn/downinfo/92.html
</
link
>
</
item
>
(item s)
</
channel
>
</
rss
>
为了获取前10条item的数据,只好土炮制造javascript如下
DOCTYPE HTML PUBLIC
"
-//W3C//DTD HTML 4.0 Transitional//EN
"
>
<
HTML
>
<
HEAD
>
<
TITLE
>
Test
SPAN style="COLOR: #000000">TITLE
>
<
script language
=
"
JavaScript
"
>
function
load()
{
var
xmlDoc
=
new
ActiveXObject(
"
Microsoft.XMLDOM
"
); xmlDoc.load(
"
rss_Down_s10.xml
"
);
var
channelNode
=
xmlDoc.documentElement.firstChild;
var
objNodeList
=
channelNode.selectNodes(
"
//item
"
);
for
(
var
count
=
0
;count
<
10
&&
count
<=
objNodeList.length;count
++
)
{
var
itemnode
=
objNodeList.item(count);
var
titleText
=
""
;
var
titleNode
=
itemnode.selectSingleNode(
"
title
"
);
if
(titleNode
!=
null
) titleText
=
titleNode.text;
var
linkText
=
""
;
var
linkNode
=
itemnode.selectSingleNode(
"
link
"
);
if
(linkNode
!=
null
) linkText
=
linkNode.text; addRow(
"
test
"
,count,titleText,linkText); }
}
function
addRow(id,index,title,link)
{
var
tbody
=
document.getElementById(id).getElementsByTagName(
"
TBODY
"
)[
0
];
var
row
=
document.createElement(
"
TR
"
)
var
td0
=
document.createElement(
"
TD
"
) td0.appendChild (document.createTextNode(index))
var
td1
=
document.createElement(
"
TD
"
) td1.appendChild(document.createTextNode(title))
var
td2
=
document.createElement(
"
TD
"
) td2.appendChild (document.createTextNode(link)) row.appendChild(td0); row.appendChild(td1); row.appendChild(td2); tbody.appendChild(row); }
SPAN style="COLOR: #000000">script
>
SPAN style="COLOR: #000000">HEAD
>
<
BODY onload
=
load()
>
<
table id
=
"
test
"
>
<
tr
>
<
td
>
1
SPAN style="COLOR: #000000">td
>
<
td
>
2
SPAN style="COLOR: #000000">td
>
<
td
>
3
SPAN style="COLOR: #000000">td
>
SPAN style="COLOR: #000000">tr
>
<
table
>
SPAN style="COLOR: #000000">BODY
>
SPAN style="COLOR: #000000">HTML
>
如果rss_Down_s10.xml可以被修改,还可以使用xsl来按格式显示数据。
|