Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    May 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to change innerhtml into table?

    Code:
    <!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <script type="text/javascript">
    var strContent = "";
    var ie = (typeof window.ActiveXObject != 'undefined');
    var moz = (typeof document.implementation != 'undefined') && 
      (typeof document.implementation.createDocument != 'undefined');
    var xmlDoc; 
    var table = false
    function importXML(file) {
      if (moz) { 
        xmlDoc = document.implementation.createDocument("", "doc", null);
        xmlDoc.onload = readXML;
        xmlDoc.load(file);
      } else if (ie) {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = false;
        while(xmlDoc.readyState != 4) {}; 
        xmlDoc.load(file);
        readXML();
      }
    }
    
    function readXML() {
      root = xmlDoc.documentElement;
      crawl(root, 0);
      if (document.getElementById) {
        document.getElementById("content").innerHTML = strContent + document.getElementById("content").innerHTML;
      } else if (document.all) {
        document.all["content"].innerHTML = strContent + document.all["content"].innerHTML;
      }
    }
    
    function crawl(node, level) {
      if (node.nodeType == 3 && isEmptyNode(node.nodeValue)) {
        // Don't process empty text nodes in Mozilla (IE ignores them anyway).
      } 
    else {
        var indent = "";
        for (var i = 0; i < level; i++) {
          indent = indent + "&nbsp;&nbsp;&nbsp;&nbsp;";
        }
    if (node.nodeName == "#text")
    {
    
    strContent = strContent + indent + "nodeText = " + node.text + "<br/>";
    
    }
    else
    {
    strContent = strContent + indent + "<A onClick='javaScript:toogle_state(this)'><font color=blue>nodeText = " + node.nodeName + "</A></font><br/>";
    }
    }
    //alert(strContent)
    
    
    if (node.firstChild) {
    
     crawl(node.firstChild, level + 1);
    
      }
    if (node.nextSibling) {
    
      crawl(node.nextSibling, level);
    }
    
    
    }
    
    function isEmptyNode(arg) {
      reg = /\n/g;
      arg = arg.replace(reg, "");
      reg = / /g;
      arg = arg.replace(reg, "");
      if (arg.length == 0) {
        return true;
      }
      return false;
    
    }
    
    function toogle_state(counter)
    {
    counter.style.display = 'none'
    }
    
    </script>
    </head>
    <body onLoad="importXML('note.xml');">
    <div id="content"></div>
    </body>
    </html>

    hi, me again:P Need abit of help here, i got i this script on the net and it work fine but i need to change it into a table but dunno how... can anyone here help? it load the xml then read it after that it check for firstchild, then check the firstchild for sibling. How to create a table that store the children in then after it finish store the children's table into it parent table?
    Last edited by liorean; 06-08-2004 at 11:45 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •