I am using the new $ .parseXML () method with jQuery 1.5 to parse a string in a valid XML object. Once I convert the string to a jQuery XML object, I can navigate the XML DOM and look for values. I can even change the values โโof different attributes. However, I cannot insert new elements into XML, although I believe that this is possible. Below is a code snippet that illustrates the problem:
var myXml = "<one attr='a'><two attr='b'/><three attr='c'><four attr='d'/></three></one>"; myXml = $.parseXML(myXml); $(myXml).find('two').attr('attr','new value'); //<-- This works alert($(myXml).find('two').attr('attr')); //<-- This works too $(myXml).find('three').append('<five>some value</five>'); //<-- Does not work alert($(myXml).find('five').text()) // <--Null
Does anyone have any ideas on this job? Thanks in advance.
source share