here’s some code that I use from one of my sites
- $.fn.xml = function () {var r=[];this.each(function(){r.push($.xml(this))});return r };
- $.xml = function(el) {
- if (window.XMLSerializer)
- return (new XMLSerializer()).serializeToString(el)
- var qw = function(s){return '"' + s.replace(/"/g,'"') + '"'};
- if (!el) return "(null)";
- var res = "";
- var tag = el.nodeName.toLowerCase();
- var tagShow = tag.charAt(0) != "#";
- if (tagShow) res += '<' + tag;
- if (el.attributes)
- res += $.map(el.attributes,function(attr){
- if (attr.specified && attr.name.charAt(0) != '$')
- return ' '+attr.name /* .toLowerCase() */ + '=' + qw(attr.value)
- }).join('');
- if (tagShow && el.nodeValue == null && !el.hasChildNodes())
- return res+" />";
- if (tagShow)
- res+= ">";
- if (el.nodeType == 8)
- res += "<!-- " + el.nodeValue + " -->";
- else if (el.nodeValue != null)
- res += el.nodeValue.toXML();
- if (el.hasChildNodes && el.hasChildNodes())
- res += $.map(el.childNodes,function(child){return $.xml(child)}).join('');
- if (tagShow) res += '</' + tag + '>';
- return res
- }
$.fn.xml returns an array of strings from a jQuery of XMLs
$.xml returns a string from an XML dom,
you probably want
I know the code works in other modern browsers, when I comment out the first few lines XMLSerializer, but I haven’t tested in IE.
Let me know how it works for you.
JΛ̊KE