Solved

Get data after clicking select option.

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error opening .xml with Excel 2013 4 30
XSLT Assistance 9 49
what are list of ebay api errors 1 19
XSLT 1.0 - Finding Substrings from the End of a String 3 10
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 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