Utl.js
Copy Code code as follows:
function createxmltree (node, indent) {
if (node = null)
Return "";
var str = "";
Switch (node.nodetype) {
Case 1://Element
STR + + "<div class= ' element ' ><<span class= ' elementname ' >" + node.nodename + "</span>";
var attrs = node.attributes;
for (var i = 0; i < attrs.length; i++)
str = Createxmlattribute (attrs[i]);
if (!node.haschildnodes ())
return str + "/></div>";
STR + + "><br/>";
var cs = Node.childnodes;
for (var i = 0; i < cs.length; i++)
str = Createxmltree (Cs[i], indent + 3);
STR + + "</<span class= ' elementname ' >" + node.nodename + "</span>></div>";
Break
Case 9://Document
var cs = Node.childnodes;
for (var i = 0; i < cs.length; i++)
str = Createxmltree (cs[i], indent);
Break
Case 3://Text
if (!/^\s*$/.test (Node.nodevalue))
STR + + "<span class= ' text ' >" + node.nodevalue + "</span><br/>";
Break
Case 7://Processinstruction
STR + + "node.nodename" +;
var attrs = node.attributes;
for (var i = 0; i < attrs.length; i++)
str = Createxmlattribute (attrs[i]);
str+= "><br/>"?
Break
Case 4://CDATA
str = "<div class= ' CDATA ' ><! [Cdata[<span class= ' cdata-content ' >] +
Node.nodevalue +
"</SPAN>]" + "]></div>";
Break
Case 8://Comment
str = "<div class= ' comment ' ><!--<span class= ' comment-content ' >" +
Node.nodevalue +
"</span>--></div>";
Break
Case 10:
str = "<div class= ' doctype ' ><! DOCTYPE "+ node.name;
if (node.publicid) {
STR + + "public" "+ Node.publicid +" "";
if (Node.systemid)
STR + + "" + Node.systemid + "" ";
}
else if (Node.systemid) {
STR + + "SYSTEM \" "+ Node.systemid +" "";
}
STR + + "></div>";
Todo:handle Custom DOCTYPE declarations (ELEMENT, ATTRIBUTE, ENTITY)
Break
Default
Alert (Node.nodetype + "\ n" + node.nodevalue);
Inspect (node);
}
return str;
}
function Inspect (obj) {
var str = "";
For (var k in obj)
str = "obj." + k + "=" + obj[k] + "\ n";
Window.alert (str);
}
function Createxmlattribute (a) {
Return "<span class= ' attribname ' >" + a.nodename + "</span><span class= ' attribvalue ' >=\ '" "+ A.nodevalue + "</span>";
}
Copy Code code as follows:
<meta http-equiv=content-type content= "text/html; charset=gb2312 ">
<script src= "Ajax test_files/utl.js" ></SCRIPT>
<link rev=stylesheet media=all href= "Ajax test_files/ajax.css" type=text/css
Rel=stylesheet>
<SCRIPT>
------------Xmlhttpobj class----------------
function Xmlhttpobject (Url,syne) {
var xmlhttp=null
var o=this
This.url=url
This. Syne=syne
This.senddata = function ()
{
if (window. XMLHttpRequest) {
XMLHttp = new XMLHttpRequest ();
else if (window. ActiveXObject) {
XMLHttp = new ActiveXObject ("Microsoft.XMLHTTP");
}
With (XMLHttp) {
Open (' Get ', This.url, this. Syne);
onreadystatechange = O.callback;
Send (NULL);
}
}
This. Callback=function ()
{
if (xmlhttp.readystate = = 4) {
if (Xmlhttp.status = = 200) {
O.debugxml ("readyState:" + xmlhttp.readystate + "<br/>")
O.debugxml ("Status:" + Xmlhttp.status + "<br/>")
O.debugxml ("<div style= ' background: #ffc margin-left:10px;border:1px solid #669;p adding:3px ' >" + createxmltree (xmlhttp.responsexml,0) + "</div>")
}
}
}
This.gettext=function ()
{
if (xmlhttp==null) {return "has not loaded XMLHttpRequest"}
if (xmlhttp.readystate==4) {return xmlhttp.responsetext}
Return xmlhttp.readystate
}
This.debugxml=function (log)
{
Try{document.getelementbyid ("Xmldebug"). Innerhtml+=log}
catch (e) {}
}
}
var xmldoc1=new xmlhttpobject ("Tree.xml", True)
</SCRIPT>
<meta content= "MSHTML 6.00.3790.2706" name=generator><body><select
Onchange= ' Xmldoc1.url=this.value;document.getelementbyid ("Xmldebug"). Innerhtml= "' >
<option Value=tree.xml selected>tree.xml</option> <option
Value=xtree.xsl>xtree.xsl</option> <option Value=/feed.asp>blog
Feed</option></select> <input onclick=xmldoc1.senddata () Type=button value=XMLDoc1.sendData () > <input Onclick=alert (Xmldoc1.gettext ()) Type=button value=xmldoc1.gettext () > <input onclick= "If" (Confirm (' Clear log? ') {document.getElementById (' Xmldebug '). innerhtml= '} ' Type=button value=clearlog>
<div id=xmldebug></div></body>
Copy Code code as follows:
HTML {
border-top-width:0px; border-left-width:0px; border-bottom-width:0px; border-right-width:0px
}
Body {
border-top-width:0px; border-left-width:0px; border-bottom-width:0px; border-right-width:0px
}
Body {
Background:buttonface; Font:message-box
}
FORM {
padding-right:0px; padding-left:0px; padding-bottom:0px; margin:0px; padding-top:0px
}
FieldSet fieldset {
margin:5px
}
BUTTON {
margin-left:5px
}
TEXTAREA {
width:100%; height:200px
}
#out {
Border-right:threeddarkshadow 1px solid; padding-right:3px; Border-top:threeddarkshadow 1px solid; margin-top:5px; padding-left:3px; Background:white; padding-bottom:3px; Border-left:threeddarkshadow 1px solid; Color:black; padding-top:3px; Border-bottom:threeddarkshadow 1px solid; Font-family:verdana
}
#srcTextContainer {
Display:none
}
. element {
padding-left:16px; Color:blue
}
. elementname {
Color:darkred
}
. attribname {
Color:red
}
. attribvalue {
Color:blue
}
. text {
padding-left:16px; Color:windowtext
}
. cdata-content {
Display:block; padding-left:16px; Border-left:gray 1px solid; Color:windowtext; Font-family:courier New; White-space:pre
}
. Comment {
padding-left:16px; Color:blue
}
. doctype {
padding-left:16px; Color:blue
}
. comment-content {
Display:block; Color:gray; Font-family:courier New; White-space:pre
}
#XMLDebug {
Border-right: #000 1px solid; padding-right:4px; Border-top: #000 1px solid; margin-top:6px; padding-left:4px; font-size:12px; BACKGROUND: #fff; padding-bottom:4px; Overflow:auto; Border-left: #000 1px solid; padding-top:4px; Border-bottom: #000 1px solid; height:400px
}