View Full Version : Extracting data using javascript...

10-01-2002, 10:15 PM

I want to extract data from an xml-sheet using javascript. I have a number of textfields in which I insert some of the data I need. So far so good.

I want to extract data from certain nodes and insert that data into a list. One of the problems is that it has to be done dynamically, it is not to be done a fixed number of times, some times it has to be done one time, other times it has to be done fourteen times.

My xml-sheet looks like this:
<?xml version="1.0" encoding="ISO8859-1" ?>

I want to extract meritid, kurskod and exdag and place them in an array so that I can extract them by looping through the array. Im planning to use javascript to do the looping part.

I appreciate any suggestions or help :-)

Many thanks in advance

Alex Vincent
10-03-2002, 03:07 AM
OK, to help you answer this we have to explore how to treat XML in IE & Mozilla / Netscape.

In Netscape / Mozilla, you can access the DOM directly from the XML document with a namespaced XHTML script element.

<!-- ... -->
<script xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
// JavaScript goes here

It's best in this context to enclose all your actions in functions; don't call them before onload if you can help it. (That's why I place the script here at the end of the document -- a practice which is usually avoided like the plague.)

In IE, the best shot you'll have is placing the XML document as an XML island:

<!-- ... -->
<!-- ... -->
<xml id="xmlDoc"><!-- xml document fragment goes here --></xml>

10-03-2002, 10:24 AM
Hello Alex!

I forgot to mention that I will only use IE, sorry.

Ill try to use xml islands.

Thanks for your advice :-)

10-03-2002, 02:05 PM
An alternative to xml dataislands is to load the xml document as an activeX object, e.g.

var xml_doc = new ActiveXObject("Microsoft.XMLDOM")
xml_doc.async = false


10-04-2002, 08:09 AM
Here's a post that may help you. Read the part about the XML ticker instead of the Javascript one...