Solved

Get data after clicking select option.

Posted on 2001-07-14
4
178 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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Path of Workbook 3 86
XML XSL Message 3 34
Help needed with Powershell  XML to MySQL 5 72
How to configure empty element in XML Document parser? 15 44
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 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