[thelist] Extracting a node from an ajax response

Eike Pierstorff eike at diebesteallerzeiten.de
Sun Nov 9 17:18:00 CST 2008

Dear list,

for a project that uses mootools as javascript library I need to do the
following: Load a page via ajax, extract a certain node (a div element
identified by id, and possibly with other attributes) including all its
child elements from the response text and insert this into the current
document (while discarding the unnecessary bits). My Problem is with the
second part, manipulating the ajax response before I insert it into the DOM.

As far as I can tell there is no mootools function that I can use for this.
I tried to get some inspiration from jquery which has a function that does
this, but that code is a bit to sophisticated for me to convert it for
mootools. For now I use regular expressions, but that means I cannot have
nested div tags in the page I'm loading (the regexp will stop at the first
closing div. We want to avoid using special markup to use with the regexp). 

The pages I load will always be valid XHTML. Since I think all modern
browsers include an XML parser I hope I can use this to parse the ajax
response as XML and so extract the wanted bit. But while I would rate my
javascript skills as intermediate I do not now how to parse XML with
Javascript (so far I could always use library code to do the job for me). 

I do not need a catch-all solution, I'm looking for a solution that solves
my specific problem with as little code as possible. I would be grateful if
somebody on the list could point me in the right direction.

Thank you,


More information about the thelist mailing list