Sanding our assholes with 150 grit.

OK here's a stupid question (XML/DOM/XMLHttpRequest)

In IE, once you instantiate the XML DOM parser you can load a text string containing XML this way:

parser.loadXML(string);

This is great since I can take the response from an XMLHttpRequest and just load it into the parser as if it were an existing xml file (something both IE and Mozilla support with the .load() method of the parser).

I've been poring through Mozilla documentation for half an hour now, and I can't find an equivalent function in the Mozilla XML DOM parser. What the hizzy? How do I do this in Mozilla?
Permalink Mark Warner 
January 12th, 2006
Mark I just use:

response = req.responseXML.documentElement;

where req is the XMLHttpRequest object... you can then just say:

result  = response.getElementsByTagName('result')[0].firstChild.data;

or whatever other DOM commands you want to issue.

This works in both browsers btw.
Permalink Phil 
January 12th, 2006
Neat.

I had a suspicion that it was simpler than the tut I was reading. :P
Permalink Mark Warner 
January 12th, 2006
If what you were looking for was to actually create an XML doc from a string (rather than from a download), you could something like this ....

xmlParser = new DOMParser();
xmlDocument = xmlParser.parseFromString(string, 'text/xml');
Permalink slava 
January 12th, 2006
Thanks, slava.
Permalink Mark Warner 
January 12th, 2006
"There are no stupid questions, only stupid people."

(g,d,r)
Permalink Anonymous A-Hole 
January 12th, 2006

This topic was orginally posted to the off-topic forum of the
Joel on Software discussion board.

Other topics: January, 2006 Other topics: January, 2006 Recent topics Recent topics