472,119 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

Concatenate XML Nodes using Javascript

Hello everyone,

I have a question on XML with Javascript. Here is my situation:

I have two xml documents (1.xml and 2.xml) with similar structure:

[HTML]<person>
<data>
<value>1</value>
<value>2</value>
</data>
</person>[/HTML]

Using Javascript, I managed to load the 1.xml document, store the <value> nodes into a variable called valueNodes.

Expand|Select|Wrap|Line Numbers
  1. var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  2. xmlDoc.load("note.xml");
  3.  
  4. var personNode = xmlDoc.getElementsByTagName("person").item(0);
  5. var dataNode = personNode.getElementsByTagName("data").item(0);
  6. valueNodes = dataNode.getElementsByTagName("value");
  7.  
My question: when I load 2.xml, is there a method to get the <value> nodes and then concatenate them to nodes that I already have in valueNodes? I have tried

Expand|Select|Wrap|Line Numbers
  1. valueNodes = valueNodes + dataNode.getElementsByTagName("value");
and
Expand|Select|Wrap|Line Numbers
  1. valueNodes = valueNodes & dataNode.getElementsByTagName("value");
but to no avail.

Any suggestions are appreciated :) Thanks!


Yenyen
Aug 16 '07 #1
2 3357
Hello again,

To clarify my question, what I need is to concatenate the results of

dataNode.getElementsByTagName("value")

to valueNodes, that is, all the nodes. Just found out there is appendChild function, to use this I will need to iterate the results and append one by one, but this will take to much resource for me as there are about 6000 nodes to append.

Thanks again for any suggestions.


Yenyen
Aug 16 '07 #2
jkmyoung
2,057 Expert 2GB
I don't know if something like this would improve performance.

http://tom-lee.blogspot.com/2006/06/...elists_08.html
joinNodeLists: function(list1,list2){
var i = list2.length - 1;

do{ list1[list1.length] = list2[i];

}
while(i--);

return list1;
}
Aug 17 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Gordon - Adelphia | last post: by
2 posts views Thread by arvindsd | last post: by
6 posts views Thread by Paul J Lay | last post: by
reply views Thread by Luis Esteban Valencia | last post: by
6 posts views Thread by Sheldon | last post: by
4 posts views Thread by javascript | last post: by
10 posts views Thread by Aaron Hoffman | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.