选择显示字体大小

让你的mozilla支持xml数据岛

由于mozilla没有内建的机制支持xml数据岛,但是mozilla提供了对dom的支持,我们可以通过dom访问xml数据岛中节点、属性等。 下面就是一个比较全面的例子:

<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
<!doctype html public &quot;-//w3c//dtd xhtml 1.0 frameset//en&quot; &quot;http://www.w3.org/tr/xhtml1/dtd/xhtml1-frameset.dtd&quot;>
<html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;>
<head>
<style type=&quot;text/css&quot;>
xml
{
width: 0px;
height: 0px;
display: none;
}
</style>
<script language=&quot;javascript&quot;>
<!-- <![cdata[
function setevents() {
mozilladso();
}

function showdso() {
if(window.navigator.appname==&quot;microsoft inte.net explorer&quot;)
{
alert(xmlone.xmldocument.xml)
alert(xmltwo.xmldocument.xml)
}
else
{
for(var i=0;i < document.getelementsbytagname('xml').length;i++)
alert(document.getelementsbytagname('xml').item(i).innerhtml);
}
}

function mozilladso() {
/* function: mozilladso
creation date: april 16, 2003
programmer: edmond woychowsky
purpose: the purpose of this function is to perform binding of
xml data islands for mozilla. the logic herein is bypassed
for microsoft inte.net explorer.

update date: programmer: description:
*/

// global variables
objxmldi = new collection(); // xml data island collection
objbound = new collection(); // bound xhtml object collection

// local variables
var objdatafld; // table datafld collection
var objrow; // table row
var rework = new regexp('inte.net explorer','gi');
var arrkeys = new array();
var intkey = 0; // objbound collection key
var introws; // row count

if(!rework.test(navigator.appname)) {
// locate data islands
for(var i=0;i < document.getelementsbytagname('xml').length;i++)
objxmldi.add('#' + document.getelementsbytagname('xml').item(i).getattribute('id'),document.getelementsbytagname('xml').item(i));

// locate bound nodes
for(var i=0;i < document.getelementsbytagname('table').length;i++)
if(document.getelementsbytagname('table').item(i).getattribute('datasrc') != null) {
objbound.add(intkey.tostring(),new boundxml());

objbound.item(intkey.tostring()).datasrc = document.getelementsbytagname('table').item(i).getattribute('datasrc');
objbound.item(intkey.tostring()).node = document.getelementsbytagname('table').item(i);
objbound.item(intkey.tostring()).nodename = document.getelementsbytagname('table').item(i).nodename;

objdatafld = new collection(); // reset collection;
introws = 0; // reset row count

// remove all rows
if(objbound.item(intkey.tostring()).node.getelementsbytagname('tr').length != 0) {
for(var j=0;j < objbound.item(intkey.tostring()).node.getelementsbytagname('tr').length;j++)
objrow = objbound.item(intkey.tostring()).node.lastchild.removechild(objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j));

for(var j=0;j < objbound.item(intkey.tostring()).node.getelementsbytagname('tr').length;j++)
objrow = objbound.item(intkey.tostring()).node.lastchild.removechild(objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j));
}

// determine bound nodes
for(var j=0;j < objrow.getelementsbytagname('input').length;j++)
if(!objdatafld.exists(objrow.getelementsbytagname('input').item(j).getattribute('datafld')))
objdatafld.item(objrow.getelementsbytagname('input').item(j).getattribute('datafld'),null);

for(var j=0;j < objrow.getelementsbytagname('div').length;j++)
if(!objdatafld.exists(objrow.getelementsbytagname('div').item(j).getattribute('datafld')))
objdatafld.item(objrow.getelementsbytagname('div').item(j).getattribute('datafld'),null);

for(var j=0;j < objrow.getelementsbytagname('span').length;j++)
if(!objdatafld.exists(objrow.getelementsbytagname('span').item(j).getattribute('datafld')))
objdatafld.item(objrow.getelementsbytagname('span').item(j).getattribute('datafld'),null);

arrkeys = objdatafld.keys();

// determine row count
for(var j=0;j < arrkeys.length;j++)
if(introws < objxmldi.item(objbound.item(intkey.tostring()).datasrc).getelementsbytagname(arrkeys[0]).length)
introws = objxmldi.item(objbound.item(intkey.tostring()).datasrc).getelementsbytagname(arrkeys[0]).length;

for(var j=0;j < introws;j++)
objbound.item(intkey.tostring()).node.lastchild.appendchild(objrow.clonenode(true));

// rebuild table and bind
for(var j=0;j < objbound.item(intkey.tostring()).node.getelementsbytagname('tr').length;j++)
for(var k=0;k < objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').length;k++)
for(var l=0;l < objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.length;l++)
switch(objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).nodename.tolowercase()) {
case('input'):
try {
if(objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).getattribute('type') != 'checkbox')
objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).value =

objxmldi.item(objbound.item(intkey.tostring()).datasrc).getelementsbytagname(objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).getattribute('datafld')).item(j).firstchild.nodevalue;
else
objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).checked = eval(objxmldi.item(objbound.item(intkey.tostring()).datasrc).getelementsbytagname(objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).getattribute('datafld')).item(j).firstchild.nodevalue);
}
catch(e) { }

if(objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).getattribute('type') != 'checkbox')
objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).onchange = new function('try { objxmldi.item(\'' + objbound.item(intkey.tostring()).datasrc + '\').getelementsbytagname(\'' + objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).getattribute('datafld') + '\').item(' + j.tostring() + ').firstchild.nodevalue = this.value } catch(e) { objxmldi.item(\'' + objbound.item(intkey.tostring()).datasrc + '\').getelementsbytagname(\'' + objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).getattribute('datafld') + '\').item(' + j.tostring() + ').appendchild(document.createtextnode(this.value)) };mozilladso;');
else
objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).onchange = new function('try { objxmldi.item(\'' + objbound.item(intkey.tostring()).datasrc + '\').getelementsbytagname(\'' + objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).getattribute('datafld') + '\').item(' + j.tostring() + ').firstchild.nodevalue = this.checked } catch(e) { objxmldi.item(\'' + objbound.item(intkey.tostring()).datasrc + '\').getelementsbytagname(\'' + objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).getattribute('datafld') + '\').item(' + j.tostring() + ').appendchild(document.createtextnode(this.checked)) };mozilladso;');

break;
case('div'):
case('span'):
try { // text node exists
objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).firstchild.nodevalue = objxmldi.item(objbound.item(intkey.tostring()).datasrc).getelementsbytagname(objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).getattribute('datafld')).item(j).firstchild.nodevalue;
}
catch(e) { // create text node
try {
objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).appendchild(document.createtextnode(objxmldi.item(objbound.item(intkey.tostring()).datasrc).getelementsbytagname(objbound.item(intkey.tostring()).node.getelementsbytagname('tr').item(j).getelementsbytagname('td').item(k).childnodes.item(l).getattribute('datafld')).item(j).firstchild.nodevalue));
}
catch(e) { }
}

break;
}

++intkey;
}

// non-tabular datasrc/datafld
for(var i=0;i < document.getelementsbytagname('input').length;i++)
if(document.getelementsbytagname('input').item(i).getattribute('datafld') != null) {
objbound.add(intkey.tostring(),new boundxml());

if(document.getelementsbytagname('input').item(i).getattribute('datasrc') != null)
objbound.item(intkey.tostring()).datasrc = document.getelementsbytagname('input').item(i).getattribute('datasrc');

objbound.item(intkey.tostring()).datafld = document.getelementsbytagname('input').item(i).getattribute('datafld');
objbound.item(intkey.tostring()).node = document.getelementsbytagname('input').item(i);
objbound.item(intkey.tostring()).nodename = document.getelementsbytagname('input').item(i).nodename;

++intkey;
}

for(var i=0;i < document.getelementsbytagname('div').length;i++)
if(document.getelementsbytagname('div').item(i).getattribute('datafld') != null) {
objbound.add(intkey.tostring(),new boundxml());

if(document.getelementsbytagname('div').item(i).getattribute('datasrc') != null)
objbound.item(intkey.tostring()).datasrc = document.getelementsbytagname('div').item(i).getattribute('datasrc');

objbound.item(intkey.tostring()).datafld = document.getelementsbytagname('div').item(i).getattribute('datafld');
objbound.item(intkey.tostring()).node = document.getelementsbytagname('div').item(i);
objbound.item(intkey.tostring()).nodename = document.getelementsbytagname('div').item(i).nodename;

++intkey;
}

for(var i=0;i < document.getelementsbytagname('span').length;i++)
if(document.getelementsbytagname('span').item(i).getattribute('datafld') != null) {
objbound.add(intkey.tostring(),new boundxml());

if(document.getelementsbytagname('span').item(i).getattribute('datasrc') != null)
objbound.item(intkey.tostring()).datasrc = document.getelementsbytagname('span').item(i).getattribute('datasrc');

objbound.item(intkey.tostring()).datafld = document.getelementsbytagname('span').item(i).getattribute('datafld');
objbound.item(intkey.tostring()).node = document.getelementsbytagname('span').item(i);
objbound.item(intkey.tostring()).nodename = document.getelementsbytagname('span').item(i).nodename;

++intkey;
}

arrkeys = objbound.keys();

// handle non-tabular binds
for(var i=0;i < arrkeys.length;i++)
switch(objbound.item(arrkeys[i]).nodename.tolowercase()) {
case('table'):
objbound.item(arrkeys[i]).rows = new array();

break;
case('input'):
try {
if(typeof(objbound.item(arrkeys[i]).datasrc) == 'string') {
try {
if(objbound.item(arrkeys[i]).node.getattribute('type') != 'checkbox')
objbound.item(arrkeys[i]).node.value = objxmldi.item(objbound.item(arrkeys[i]).datasrc).getelementsbytagname(objbound.item(arrkeys[i]).datafld).item(0).firstchild.nodevalue;
else
objbound.item(arrkeys[i]).node.checked = eval(objxmldi.item(objbound.item(arrkeys[i]).datasrc).getelementsbytagname(objbound.item(arrkeys[i]).datafld).item(0).firstchild.nodevalue);
}
catch(e) { }

if(objbound.item(arrkeys[i]).node.getattribute('type') != 'checkbox')
objbound.item(arrkeys[i]).node.onchange = new function('try { objxmldi.item(this.getattribute(\'datasrc\')).getelementsbytagname(this.getattribute(\'datafld\')).item(0).firstchild.nodevalue = this.value } catch(e) { objxmldi.item(this.getattribute(\'datasrc\')).getelementsbytagname(this.getattribute(\'datafld\')).item(0).appendchild(document.createtextnode(this.value)) };mozilladso()');
else
objbound.item(arrkeys[i]).node.onclick = new function('try { objxmldi.item(this.getattribute(\'datasrc\')).getelementsbytagname(this.getattribute(\'datafld\')).item(0).firstchild.nodevalue = this.checked } catch(e) { objxmldi.item(this.getattribute(\'datasrc\')).getelementsbytagname(this.getattribute(\'datafld\')).item(0).appendchild(document.createtextnode(this.checked)) };mozilladso()');
}
}
catch(e) { }

break;
case('div'):
case('span'):
if(typeof(objbound.item(arrkeys[i]).datasrc) == 'string') {
try { // text node exists
objbound.item(arrkeys[i]).node.firstchild.nodevalue = objxmldi.item(objbound.item(arrkeys[i]).datasrc).getelementsbytagname(objbound.item(arrkeys[i]).datafld).item(0).firstchild.nodevalue;
}
catch(e) { // create text node
try {
objbound.item(arrkeys[i]).node.appendchild(document.createtextnode(objxmldi.item(objbound.item(arrkeys[i]).datasrc).getelementsbytagname(objbound.item(arrkeys[i]).datafld).item(0).firstchild.nodevalue));
}
catch(e) { }
}
}

break;
default:
alert('error: unsupported html element - ' + objbound.item(arrkeys[i]).nodename.tolowercase());

break;
}
}

function boundxml() {
var datasrc = null; // data source (string)
var datafld = null; // data field (string)
var node = null; // xhtml node (object)
var nodename = null; // node name (string)
}
}

function collection() {
/* function: collection
creation date: august 16, 2002
programmer: edmond woychowsky
purpose: the purpose of this class is to define the collection
object associative array.

update date: programmer: description:
*/

// properties
this.objcollection = new object; // associative array
this.count = 0; // total numbers of items

// methods
this.add = coladd; // add method
this.exists = colexists; // exists method
this.item = colitem; // item method
this.removeall = colremoveall; // remove all method
this.remove = colremove; // remove method
this.keys = colkeys; // keys method

function coladd(strkey,stritem) {
/* function: coladd
creation date: august 16, 2002
programmer: edmond woychowsky
purpose: the purpose of this function is to add an item to
the collection object.

update date: programmer: description:
*/

if(typeof(this.objcollection[strkey]) == 'undefined')
++this.count;

this.objcollection[strkey] = stritem;
}

function colexists(strkey) {
/* function: colexists
creation date: august 16, 2002
programmer: edmond woychowsky
purpose: the purpose of this function is to return a boolean
indicating where or not a key exists in the
collection object.

update date: programmer: description:
*/

if(typeof(this.objcollection[strkey]) == 'undefined')
return false;
else
return true;
}

function colitem(strkey,stritem) {
/* function: colitem
creation date: august 16, 2002
programmer: edmond woychowsky
purpose: the purpose of this function is to either set or get
an item to or from the collection object.

update date: programmer: description:
*/

if(typeof(stritem) == 'undefined')
return this.objcollection[strkey];
else {
if(typeof(this.objcollection[strkey]) == 'undefined')
++this.count;

this.objcollection[strkey] = stritem;
}
}

function colremoveall() {
/* function: colremoveall
creation date: august 16, 2002
programmer: edmond woychowsky
purpose: the purpose of this function is to remove all keys
and items from the collection object and set the
item count to zero.

update date: programmer: description:
*/

this.objcollection = new object;
this.count = 0;
}

function colremove(strkey) {
/* function: colremove
creation date: august 16, 2002
programmer: edmond woychowsky
purpose: the purpose of this function is to remove a single
item and it's associated key from the collection
object and decrement the count by one.

update date: programmer: description:
*/

if(typeof(stritem) != 'undefined') {
this.objcollection[strkey] == 'undefined';
--this.count;
}
}

function colkeys() {
/* function: colkeys
creation date: august 16, 2002
programmer: edmond woychowsky
purpose: the purpose of this function is to return an array
consisting of the collection object's keys.

update date: programmer: description:
*/

var arrwork = new array();
var strkey;

for(strkey in this.objcollection)
if(this.objcollection[strkey] != 'undefined')
arrwork.push(strkey);

return arrwork;
}
}
// ]]> -->
</script>
</head>
<body onload=&quot;setevents()&quot;>
<table width=&quot;20%&quot;>
<tr>
<td>
<input type=&quot;text&quot; id=&quot;input&quot; datasrc=&quot;#xmlone&quot; datafld=&quot;first&quot; />
</td>
</tr>
<tr>
<td>
<div id=&quot;div&quot; datasrc=&quot;#xmlone&quot; datafld=&quot;second&quot;></div>
</td>
</tr>
<tr>
<td>
<span id=&quot;span&quot; datasrc=&quot;#xmlone&quot; datafld=&quot;third&quot;></span>
</td>
</tr>
<tr>
<td>
<input type=&quot;checkbox&quot; id=&quot;input&quot; datasrc=&quot;#xmlone&quot; datafld=&quot;check&quot; />
</td>
</tr>
</table>
<table datasrc=&quot;#xmltwo&quot; border=&quot;1&quot;>
<thead>
<td bgcolor=&quot;#ffffee&quot;>line</td>
<td bgcolor=&quot;#ffffee&quot;>word</td>
<td bgcolor=&quot;#ffffee&quot;>color</td>
<td bgcolor=&quot;#ffffee&quot;>true/false</td>
</thead>
<tr>
<td>
<div datafld=&quot;line&quot;></div>
</td>
<td>
<span datafld=&quot;word&quot;></span>
</td>
<td>
<input type=&quot;text&quot; id=&quot;input&quot; datafld=&quot;color&quot; />
</td>
<td>
<input type=&quot;checkbox&quot; id=&quot;input&quot; datafld=&quot;check&quot; />
</td>
</tr>
</table>
<br />
<input type=&quot;button&quot; onclick=&quot;showdso()&quot; value=&quot;show data islands&quot; />
<xml id=&quot;xmlone&quot; async=&quot;false&quot;>
<root>
<first></first>
<second>plugh</second>
<third></third>
<check></check>
</root>
</xml>
<xml id=&quot;xmltwo&quot; async=&quot;false&quot;>
<root>
<row>
<line>1</line>
<word>one</word>
<color>red</color>
<check></check>
</row>
<row>
<line>2</line>
<word>two</word>
<color></color>
<check>false</check>
</row>
<row>
<line>3</line>
<word>three</word>
<color>blue</color>
<check>true</check>
</row>
</root>
</xml>
</body>
</html>

  


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons