Keith Kaiser

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromKeith Kaiser
ToMe
SubjectAfter running importXML () then what?
Date8 February 2005 5:21
I've successfully used importXML() to import an XML file to my web
page, but I don't understand the statement 'When the xml file has
loaded, the named function will be run, and will be passed a reference
to the document
object of the XML file. You can then manipulate the data in the file
using W3C DOM scripting.'

I did use a simple javascript alert to verify that it runs but I don't
know how to actually access the information with the DOM script. I'm
hoping you could give me a little example I could place in my page to
find and display specific parts of the file. I've put what I have in
my page already (even if it doesn't do anything) in hopes you'll take
a look at it for me.

My web page and section is at: [sample address]
The XML file is at url: [XML file ddress]
Below is the code in my page that I wish to use to display the results
of the search;

[a form that should be used to load the XML file]

I appreciate any thing you can do for me and thank you well in advance
for your time.

-- 
Keith Kaiser
FromMe
ToKeith Kaiser
SubjectRe: After running importXML () then what?
Date9 February 2005 10:05
Keith,

There are two stages to importing an XML file.
1. loading the XML file
2. using the data in the XML file

My script takes care of part 1. You have to write your own function to
extract whatever data you want, and display it however you want.

This call:
importXML( 'commishList.xml', '' );
needs to contain the name of your function that will extract the data.

For example:
importXML( 'commishList.xml', 'myfunction' );
... then you need some script that will process the document ...
function myfunction(oDoc) {
 //oDoc is now a reference to the document object of your XML file
 //This is just like any DOM script, where you use the word document
 //to access other parts of the file - this is just an example, it would
 //depend entirely on your XML file, what it contains, and what you
 //want to display
 var x = oDoc.getElementsByTagName('mytags');
 alert(x[0].firstChild.nodeValue);
 ... etc. - some code that extracts the data and displays it ...
}

If you do not know about DOM, what it is and how you use it, you might want
to take a look at my DOM scripting tutorial:
http://www.howtocreate.co.uk/tutorials/javascript/dombasics

As a more serious note, your XML file is encoded using EBCDIC, which turns
it into complete garbage in most browsers (I am assuming you are using
Internet Explorer, so open the file in that then 'View - source' - that is
what most other browsers will see). EBCDIC is designed for use in IBM
mainframes. On the web, it is more usual to use something like UTF-8 (which
all browsers understand). If you have to option to change that encoding, I
recommend you do so.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.