Since I just struggled with this for a couple of hours, I figured I’d post it here for posterity.
If you want to generate the string representation of some XML in JavaScript, here’s how to do it (using the Prototype 1.6 syntax for element creation), courtesy of Captain’s Universe:
var contactsElement = new Element("contacts");
var evanElement = new Element("contact");
Element.insert(evanElement, new Element("name").update("Evan DiBiase"));
Element.insert(evanElement, new Element("blog", {'type': 'personal'}).update("http://evand.org"));
Element.insert(evanElement, new Element("email", {'type': 'school'}).update('esd@cmu.edu'))
Element.insert(contactsElement, evanElement);
var zachElement = new Element("contact");
Element.insert(zachElement, new Element("name").update("Zach Paine"));
Element.insert(zachElement, new Element("blog", {'type': 'personal'}).update("http://zachpaine.info"));
Element.insert(contactsElement, zachElement);
alert(new XMLSerializer().serializeToString(contactsElement));
I don’t know if this works with IE yet; I’ll update this post when I find out.