Solved

Get data after clicking select option.

Posted on 2001-07-14
4
173 Views
Last Modified: 2008-03-06
I am going through SAMS Teach Yourself XML in 24 Hours (and I don't need comments on the good and bad of that just yet).  I am up to chapter 4 where it is dealing with data islands. The object is to build a select list through an XML doc of a list of other XML files.  This works.  Then click a button to open the selected XML file.  This does not work.  The ActiveXObject is created and then loaded.  The readyState only ever gets to "3"

I thought it might be a time thing so I created a javascript delay.  This worked in an earlier example for me.  It doesn't work this time though.  My PC is PIII 1Ghz, 384MB, Windows 2000 Pro.  Any ideas?  The opening part of the code is below (I can post the whole thing if you need it).

var y = 0
function LoadFile() {
  /* The ActiveXObject will be the one that links to the message to be read.
  We load the file name that was selected. */
  var xmlDoc1 = new ActiveXObject("microsoft.xmldom")
  xmlDoc1.async = false
  xmlDoc1.setProperty "ServerHTTPRequest", false
  xmlDoc1.load(document.forms[0].elements["select1"].value)
  if (xmlDoc1.readyState>3) {
    // loopindex is the counter that traverses through the nodes
    var loopindex, RottElement1, nodecount
    RootElement1 = xmlDoc1.documentElement
    if (RootElement1==null) {
      alert("The root node is null")
      document.write("<b><big>The data of the XML file can not be accessed</big></b>")
    } else {
      // Now we extract the number of nodes in the list
      nodecount = RootElement1.childNodes.length
      for (loopindex=0;loopindex<nodecount;loopindex++) {
        // This line will write the name of the node to the body section of the HTML file
        document.write(RootElement1.childNodes.item(loopindex).nodeName)
        // This line will write out the contents of the node to the body section of the HTML file
        document.write(RootElement1.childNodes.item(loopindex).text + "<br>")
      }
    }
  } else {
    if (y<50) {
      y += 1
      setTimeout("LoadFile()",50)
    } else {
      alert(xmlDoc1.readyState)
      alert("Process could not start")
    }
  }
}
0
Comment
Question by:dij8
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
mattyk earned 100 total points
Comment Utility
On my machine the only thing that needed to be modified was  the removal of this line of code:

 xmlDoc1.setProperty "ServerHTTPRequest",false

The only other thing that could be causing a problem would be with the paths of the xml files.  From this example it looks as if all of the xml files should be in the same folder as the html page.

Also have you downloaded the source code for the book to compare?
http://www.mcp.com/sams/display_sams.cfm?item=0672319500&itemhdr=Source%20Code&itemloc=sourcecode

cheers,
matty
0
 
LVL 10

Author Comment

by:dij8
Comment Utility
Excellent.  That did it.

That line and the previous one was actually code I found in somebody else's question here at EE.  I had to change the code a reasonable amount to get it to work at all so looking at the source code on the net probably wouldn't have helped me anyway.  I had no idea what either of those extra lines did so I just assumed they went together (as that was part of the point of the other question in the PAQ here).

Do you know what they do?  Or will I find out later in the book?  One thing I have found already is I no longer need my delay loop waiting for the file to load.

It looks like the book needs a bit of thinking regarding the code because it may not always work exactly as promised. :-(  Good job I have at least some idea, and a place to go when I don't know.
0
 
LVL 5

Expert Comment

by:mattyk
Comment Utility
Glad to help.  Here's some info on those lines of code to look over:

Async:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmproasync.asp

setProperty:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmmthsetproperty.asp

and for future refernence here's the link to Microsoft's XMl reference whihc will give you info on all of the available objects,properties etc.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmmscxmlreference.asp


cheers,
matty
0
 
LVL 10

Author Comment

by:dij8
Comment Utility
Fantastic links.  Added to my Y! Bookmarks.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now