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
    Apr 2005
    Location
    Massachusetts, US
    Posts
    37
    Thanks
    5
    Thanked 0 Times in 0 Posts

    XML DOM and Tables

    Hey all,

    I am trying to make a little test page (using the digg API) that basically just lists all of the attributes of each <digg> tag in a table.

    All of the attributes list fine, except the text will not go inside table cells.

    Here is the page in action so you can see what I mean:
    http://foreverzero.org/GWT/diggtest.html
    NOTE: This only works in Firefox for the time being.

    Here is the XML is outputs:
    http://services.digg.com/stories/dig...pidoc.digg.com

    Here is the code:
    Code:
    <html>
    
    <head>
      <title> Digg API Test </title>
      <script type="text/javascript"> 
        // Function to load an XML DOM from a string of XML
        function loadXMLString(txt) {
          parser = new DOMParser();
          xmlDoc = parser.parseFromString(txt,"text/xml");
          return(xmlDoc);
        }
      </script>
    </head>
    
    <body onload="doAjax('http://services.digg.com/stories/diggs?appkey=http%3A%2F%2Fapidoc.digg.com');">
    
    <script type="text/javascript">
      // Function to load up the XML and then pass it to loadXMLString with responseText
      function doAjax(url) {
        xmlHttp = new XMLHttpRequest();
        xmlHttp.onreadystatechange=function() {
          // What to do once the XML responseText string has been loaded
          if (xmlHttp.readyState == 4) {
              // Load up an XML DOM
              xmlDoc = loadXMLString(xmlHttp.responseText);
              document.getElementById("myDiv").innerHTML = "<table border=1 cellpadding=4><tr><td>Date:</td><td>Story:</td><td>ID:</td><td>User:</td><td>Status:</td></tr>";
              // Date, Story, ID, User, Status
              diggsArray = xmlDoc.getElementsByTagName("digg");
              // For each <digg /> element...
              for (var i = 0; i < diggsArray.length; i++) {
                  document.getElementById("myDiv").innerHTML += "<tr>";
                  // Get a list of attributes from this <digg /> element
                  currentAttributes = diggsArray[i].attributes;
                  // Set variables for readability
                  var date = currentAttributes.getNamedItem("date").value;
                  var story = currentAttributes.getNamedItem("story").value;
                  var id = currentAttributes.getNamedItem("id").value;
                  var user = currentAttributes.getNamedItem("user").value;
                  var status = currentAttributes.getNamedItem("status").value;
                  // Put information inside cells
                  document.getElementById("myDiv").innerHTML += "<td>"+date+"</td>";
                  document.getElementById("myDiv").innerHTML += "<td>"+story+"</td>";
                  document.getElementById("myDiv").innerHTML += "<td>"+id+"</td>";
                  document.getElementById("myDiv").innerHTML += "<td>"+user+"</td>";
                  document.getElementById("myDiv").innerHTML += "<td>"+status+"</td>";
                  document.getElementById("myDiv").innerHTML += "</tr>";
              } // for
            document.getElementById("myDiv").innerHTML += "</table>";
          } // if
      } // function
      xmlHttp.open("GET","php_proxy_simple.php?yws_path="+url,true);
      xmlHttp.send(null);
    }
    </script>
    
    <div id="myDiv">
    This should change.
    </div>
    
    </body>
    
    </html>
    The data is all printed out, but none of it has <td> or <tr> tags wrapped around it.

    You can see in this separate page that the data does indeed import correctly, it just won;t apply td or tr tags.
    http://foreverzero.org/GWT/diggtest3.html

    Any help would be much appreciated
    Last edited by Forever Zero; 07-01-2008 at 09:17 PM.


 

Posting Permissions

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