Posted on 2006-02-15 22:58 
BlueO2 阅读(947) 
评论(0)  编辑  收藏  所属分类: 
AJAX 
			 
			
		 
		 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 <HTML>
<HTML>
 <HEAD>
<HEAD>
 <TITLE> New Document </TITLE>
<TITLE> New Document </TITLE>
 <META NAME="Generator" CONTENT="EditPlus">
<META NAME="Generator" CONTENT="EditPlus">
 <META NAME="Author" CONTENT="">
<META NAME="Author" CONTENT="">
 <META NAME="Keywords" CONTENT="">
<META NAME="Keywords" CONTENT="">
 <META NAME="Description" CONTENT="">
<META NAME="Description" CONTENT="">

 <script language="javascript" type="text/javascript">
<script language="javascript" type="text/javascript">
 var xDoc;
var xDoc;
 // verify that browser supports XML features and load external .xml file
// verify that browser supports XML features and load external .xml file
 //this method is from other people's :)
//this method is from other people's :)

 function verifySupport(xFile)
function verifySupport(xFile)  {
{

 if (document.implementation && document.implementation.createDocument)
    if (document.implementation && document.implementation.createDocument)  {
{
 // this is the W3C DOM way, supported so far only in NN6+
        // this is the W3C DOM way, supported so far only in NN6+
 xDoc = document.implementation.createDocument("", "theXdoc", null);
        xDoc = document.implementation.createDocument("", "theXdoc", null);

 } else if (typeof ActiveXObject != "undefined")
    } else if (typeof ActiveXObject != "undefined")  {
{
 // make sure real object is supported (sorry, IE5/Mac)
        // make sure real object is supported (sorry, IE5/Mac)

 if (document.getElementById("msxml").async)
        if (document.getElementById("msxml").async)  {
{
 xDoc = new ActiveXObject("Msxml.DOMDocument");
            xDoc = new ActiveXObject("Msxml.DOMDocument");
 }
        }
 }
    }

 if (xDoc && typeof xDoc.load != "undefined")
    if (xDoc && typeof xDoc.load != "undefined")  {
{
 // load external file (from same domain)
        // load external file (from same domain)
 xDoc.load(xFile);
        xDoc.load(xFile);
 return true;
        return true;

 } else
    } else  {
{
 var reply = confirm("This example requires a browser with XML support, " +
        var reply = confirm("This example requires a browser with XML support, " +
 "such as IE5+/Windows or Netscape 6+.\n \nGo back to previous page?");
            "such as IE5+/Windows or Netscape 6+.\n \nGo back to previous page?");

 if (reply)
        if (reply)  {
{
 history.back( );
            history.back( );
 }
        }
 }
    }
 return false;
    return false;
 }
}


 function init(xFile)
function init(xFile)  {
{
 // confirm browser supports needed features and load .xml file
    // confirm browser supports needed features and load .xml file

 if (verifySupport(xFile))
    if (verifySupport(xFile))  {
{
 drawTable('matchData');
        drawTable('matchData');
 }
    }
 }
}

 function drawTable(tbody)
function drawTable(tbody)  {
{
 var tr, td, i, j, oneRecord;
    var tr, td, i, j, oneRecord;
 tbody = document.getElementById(tbody);
    tbody = document.getElementById(tbody);
 // node tree
    // node tree
 var data = xDoc.getElementsByTagName("Data")[0];
    var data = xDoc.getElementsByTagName("Data")[0];
 // for td class attributes
    // for td class attributes
 var classes = ["ctr","","","","ctr"];
    var classes = ["ctr","","","","ctr"];

 for (i = 0; i < data.childNodes.length; i++)
    for (i = 0; i < data.childNodes.length; i++)  {
{
 // use only 1st level element nodes to skip 1st level text nodes in NN
        // use only 1st level element nodes to skip 1st level text nodes in NN

 if (data.childNodes[i].nodeType == 1)
        if (data.childNodes[i].nodeType == 1)  {
{
 // one final match record
            // one final match record
 oneRecord = data.childNodes[i];
            oneRecord = data.childNodes[i];
 tr = tbody.insertRow(tbody.rows.length);
            tr = tbody.insertRow(tbody.rows.length);
 td = tr.insertCell(tr.cells.length);
            td = tr.insertCell(tr.cells.length);
 td.setAttribute("class",classes[tr.cells.length-1]);
            td.setAttribute("class",classes[tr.cells.length-1]);
 td.innerHTML =
            td.innerHTML = 
 oneRecord.getElementsByTagName("N001")[0].firstChild.nodeValue;
              oneRecord.getElementsByTagName("N001")[0].firstChild.nodeValue;
 td = tr.insertCell(tr.cells.length);
            td = tr.insertCell(tr.cells.length);
 td.setAttribute("class",classes[tr.cells.length-1]);
            td.setAttribute("class",classes[tr.cells.length-1]);
 td.innerHTML =
            td.innerHTML = 
 oneRecord.getElementsByTagName("N002")[0].firstChild.nodeValue;
               oneRecord.getElementsByTagName("N002")[0].firstChild.nodeValue;
 td = tr.insertCell(tr.cells.length);
            td = tr.insertCell(tr.cells.length);
 td.setAttribute("class",classes[tr.cells.length-1]);
            td.setAttribute("class",classes[tr.cells.length-1]);
 td.innerHTML =
            td.innerHTML = 
 oneRecord.getElementsByTagName("N003")[0].firstChild.nodeValue;
               oneRecord.getElementsByTagName("N003")[0].firstChild.nodeValue;
 }
        }
 }
    }
 }
}
 </script>
</script>
 </HEAD>
</HEAD>

 <BODY onload="init('index.xml');">
<BODY onload="init('index.xml');">

 <table id="cupFinals">
<table id="cupFinals">
 <thead>
<thead>
 <tr><th>NODE1</th>
<tr><th>NODE1</th>
 <th>NODE2</th>
    <th>NODE2</th>
 <th>NODE3</th>
    <th>NODE3</th>
 </tr>
</tr>
 </thead>
</thead>
 <tbody id="matchData"></tbody>
<tbody id="matchData"></tbody>
 </table>
</table>
 <!-- Try to load Msxml.DOMDocument ActiveX to assist support verification -->
<!-- Try to load Msxml.DOMDocument ActiveX to assist support verification -->
 <object id="msxml" width="1" height="1"
<object id="msxml" width="1" height="1" 
 classid="CLSID:2933BF90-7B36-11d2-B20E-00C04F983E60" ></object>
    classid="CLSID:2933BF90-7B36-11d2-B20E-00C04F983E60" ></object>
 </BODY>
</BODY>
 </HTML>
</HTML>

XML file:
 <?xml version="1.0" encoding="gb2312"?>
<?xml version="1.0" encoding="gb2312"?>
 <Datas>
<Datas>
 <Data>
    <Data>
 <!--大循环的名称-->
<!--大循环的名称-->
 <Title>
        <Title>
 <N001>去掉HTML的第一段文字</N001>
            <N001>去掉HTML的第一段文字</N001>
 <N002>去掉HTML的第二段文字</N002>
            <N002>去掉HTML的第二段文字</N002>
 <N003>去掉HTML的第三段文字</N003>
            <N003>去掉HTML的第三段文字</N003>
 </Title>
        </Title>
 <Title>
        <Title>
 <N001>去掉HTML的第一段文字</N001>
            <N001>去掉HTML的第一段文字</N001> 
 <N002>去掉HTML的第二段文字</N002>
            <N002>去掉HTML的第二段文字</N002>
 <N003>去掉HTML的第三段文字</N003>
            <N003>去掉HTML的第三段文字</N003>
 </Title>
        </Title>
 </Data>
    </Data>
 </Datas>
</Datas>
