Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get data after clicking select option.

Posted on 2001-07-14
4
Medium Priority
?
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
mattyk earned 400 total points
ID: 6283428
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
ID: 6283789
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
ID: 6283861
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
ID: 6284074
Fantastic links.  Added to my Y! Bookmarks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

721 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