Solved

Get data after clicking select option.

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

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

Suggested Solutions

Title # Comments Views Activity
Image decoding from Camera 3 108
Extract XML Data from using TSQL 5 76
Powershell XML in variable 4 42
DTD and JAVA versions 1 55
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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