I am new to javascript and the XMLDOM, this is my first post in th forum :)
I am trying to populate the content of a javascript created explorer tree using an XML document. Below is a snip of code outlining where I am running into a problem. I have loaded a document but I can't seem to access the content and apply it to the constructer argument for my new leaf method, which takes a text string and a link argument.
Leaf Constructor:
Expand|Select|Wrap|Line Numbers
- function leaf(text, link)
- {
- this.text = text;
- this.link = link;
- this.write = writeLeaf;
- }
Expand|Select|Wrap|Line Numbers
- function main()
- {
- //experiment code
- xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.load("db.xml");
- var x = xmlDoc.getElementsByTagName('Manual');
- var myTree = new tree();
- var branch1 = new branch(branch1,'Maintennace Manuals');
- var branch2 = new branch('branch2','B 737 MEL');
- // loop for leaves
- for (j=0;j<x[0].childNodes.length;j++)
- {
- if (x[0].childNodes[j].nodeType != 1) continue;
- branch2.add(new leaf('Leaf 1','http://yahoo.com'));
- }
- branch1.add(branch2);
- myTree.add(branch1);
- myTree.write();
- }
Expand|Select|Wrap|Line Numbers
- <Manuals>
- <Manual name="'B737 MEL'">
- <Section_00 name='http://yahoo.com'>Section_00</Section_00>
- <Section_01 name='http://msn.com'>Section_01</Section_01>
- </Manual>
- </Manuals>
You will notice I am using garbadge parameters in the new leaf constructor. I want set the name and path from the content of the XMl file. When I use code to replace the argument strings I will end up ith things like undefined or [object].
Any ideas as to what I amy be doing wrong.
Thanks in advance.