String to DOM
I was working on a Greasemonkey script yesterday, and I ran into a problem for a second time. I had data (in this case, XML, in the previous case, HTML) that I had retrieved via GM_xmlhttpRequest() (Greasemonkey's cross-site-capable and slightly more flexible implementation of the XMLHTTPRequest object). I wanted to grab some small piece of information out of the huge string, but the easiest way to do this that I could think of was with big ugly Regular Expressions. The data was goddamn XML, why couldn't I use DOM? The ideal solution would be if Greasemonkey added a responseDocument field to the data that it passes to the onload callback. Since the ideal solution is not currently available, I had to cobble something else together.
Update 9 Nov: I found a far better solution today. I can hardly believe it.
var xmlDoc;
if (typeof(DOMParser) != "undefined") {
var parser = new DOMParser();
xmlDoc = parser.parseFromString(x, "application/xhtml+xml");
}