Aaldrik Sillius

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromAaldrik Sillius
ToMe
SubjectQuestion about the importXML script
Date6 October 2004 11:11
Hello Mark,

First of all: thank you very much for setting up such a wonderful
website; wish I had stumbled across it much much earlier!

May I bother you with a question regarding your importXML script?

In the example you provide on your site the call
  --- importXML('emperors.xml',createTable)
has the effect of loading the XML file and calling
  --- createTable(xmlDoc)
where xmlDoc is a reference to the XML file just loaded.

I have been struggling to get the following to work: what if I wanted to
use the same XML data in another function, e.g.:
  --- createTable(xmlDoc); createAnotherTable(....)?

Just calling createAnotherTable(xmlDoc) throws an error, because xmlDoc
isn't a global variable. I just can't find a way to 'make it global'
(ofcourse this is due to my lack of a deep understanding of JavaScript)

Since I couldn't solve this issue, I haven' even started working on the
next one: what if I wanted to use two separate XML files in one and the
same function, e.g. using 'emperors.xml' and 'moreEmperors.xml' in the
function createTable.

Any help or hints are highly appreciated.

Kind regards,

Aaldrik Sillius
FromMe
ToAaldrik Sillius
SubjectRe: Question about the importXML script
Date6 October 2004 14:31
Aaldrik,

> First of all: thank you very much for setting up such a wonderful
> website; wish I had stumbled across it much much earlier!

always happy to help :)

> importXML('emperors.xml',createTable)

note, the function name should be in quotes
importXML('emperors.xml','createTable')

> I have been struggling to get the following to work: what if I wanted
> to use the same XML data in another function?

function createTable(xmlDoc) {
 ...run another function...
 createAnotherTable(xmlDoc);
 ...store for later (make it global as storedDoc)...
 window.storedDoc = xmlDoc;
}

> what if I wanted to use two separate XML files in one and the
> same function, e.g. using 'emperors.xml' and 'moreEmperors.xml' in
> the function createTable.

well, the function simply receives a document object. it has no idea what
is in it, or what it was originally called. Assuming the format of the XML
in the files is correct, the same function can be used as many times as
needed, with as many different files as needed.

if you need to process the two files together (for example, to use the
contents of one file to manipulate the contents of the other file), use
separate functions to store the two document objects, and when they are
both loaded, call the processing function

function store1(oDoc) {
 window.storedDoc1 = oDoc;
 if( window.storedDoc2 ) { processFiles(storedDoc1,storedDoc2); }
}
function store2(oDoc) {
 window.storedDoc2 = oDoc;
 if( window.storedDoc1 ) { processFiles(storedDoc1,storedDoc2); }
}
function processFiles(oDoc1,oDoc2) {
 ... process the files ...
}
importXML( 'emperors.xml', 'store1' );
importXML( 'slaves.xml', 'store2' );


Hope this helps explain it all for you

Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromAaldrik Sillius
ToMe
SubjectRe: Question about the importXML script
Date7 October 2004 10:03
Hello Mark,

Thank you for your swift response.

> Re: Question about the importXML script
> ... (answers and tips snipped)
> Hope this helps explain it all for you

Your answers and tips have put me right back on track!

So: scripters_with_uplifted_spirit++

A 10^6 thanks,

Aaldrik Sillius
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.