suppose I have two strings with XML inside. Something like this:
<playlist>
<item id="1">
...
</item>
</playlist>
and
<playlist>
<item id="2">
...
</item>
</playlist>
What I want to obtain is this:
<playlist>
<item id="1">
...
</item>
<item id="2">
...
</item>
</playlist>
Then I do this:
oldPlaylist = $.parseXML(string1);
newPlaylist = $.parseXML(string2);
$(oldPlaylist).find('playlist').each(function(index,playlist) {
$(newPlaylist).find('item').each(function(index2,item) {
$(playlist).add(item);
});
});
answer = (new XMLSerializer()).serializeToString(oldPlaylist);
But it doesn't work. Answer is the same that string1. I can say that with the example supplied, this enters to the first each one time, and to the second each one time too (then seems that it reads correctly both XML).
What do you think? Can you help me? Thank you!
add()is the wrong thing to use. It merely adds the item to the set of matched elements... it does not insert a new child element into a DOM tree.