Changing XML DOM with JQuery not working
in Using jQuery
•
10 years ago
Hi,
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:
- $(xmlDOM).find('Table [name="'+tabela+'"]').each(function(){
- $(this).attr("confirmation","true");
- });
- 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:
- var tables = xmlDOM.getElementsByTagName("Table");
- for(var i = 0; i < tables.length; i++){
- if(tables[i].getAttribute("name") == tabela){
- tables[i].setAttribute("confirmation","true");
- }
- }
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:
- var current = $(xmlDOM).find('Table [name="'+tabela+'"]');
- current.attr("confirmation", "true");
- 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:
- function XMLToString(oXML) {
- if (window.ActiveXObject) {
- return oXML.xml;
- } else {
- return (new XMLSerializer()).serializeToString(oXML);
- }
- }
It works with xmlDOM but not with $(xmlDOM).
Could someone help me and say what I'm doing wrong???
Glad if someone can help! =)
1