Changing XML DOM with JQuery not working

Changing XML DOM with JQuery not working


This is my first post in this forum, and I hope someone can answer me. 

I'm trying to edit (change attributes) an XML DOM I downloaded from server, with JQuery, but I was unable to do so. I could do it just using (pure) Javascript.

So, this doesn't work:

  1. $(xmlDOM).find('Table [name="'+tabela+'"]').each(function(){
  2.       $(this).attr("confirmation","true");
  3. });

  4. console.log(XMLToString(xmlDOM));

When I check the console, the attribute confirmation is with it old value (false).

This is working according to my last test:

  1. var tables = xmlDOM.getElementsByTagName("Table");
  2. for(var i = 0; i < tables.length; i++){
  3.       if(tables[i].getAttribute("name") == tabela){
  4.             tables[i].setAttribute("confirmation","true");
  5.       }
  6. }

When I use "$(xmlDOM)" I can get all the attributes and loop through nodes (find, next, parent, etc...), but updating attributes is not working.

What I could do was something like this:

  1. var current = $(xmlDOM).find('Table [name="'+tabela+'"]');

  2. current.attr("confirmation", "true");

  3. console.log(current.attr("confirmation"));

and checking the console, the value of confirmation is "true", but printing the xmlDOM shows me the attribute unchanged. (I'm not using .each function here because I have only one element that match that name).

Also, the XML2String function is this:

  1. function XMLToString(oXML) {  
  2. if (window.ActiveXObject) {     
  3. return oXML.xml;   
  4. } else {     
  5. return (new XMLSerializer()).serializeToString(oXML);   
  6. }

It works with xmlDOM but not with $(xmlDOM).

Could someone help me and say what I'm doing wrong??? 

Glad if someone can help! =)