[jQuery] Parsing XHTML fragment.

[jQuery] Parsing XHTML fragment.


Hello,
I have the following problem, I hope JQuery may help. I will firstly
introduce the JavaScript problem.
I register a mutation listener on a DIV element. When a node is
inserted to the DIV I use the event object passed to my listener to
retrieve the node inserted. It could look like this.
<span class="message">
<b>Name</b>

Hello World!


</span>
Currently I parse this XHTML fragment using various DOM methods such
as
hasChildNodes(), nextSibling, previousSibling, etc (you get the idea).
However it is possible that the XHTML fragment that is inserted may
change, for example once every 2 months. I have attempted to make my
JavaScript as loosely coupled with the XHTML fragment as possible, but
do not feel this goes far enough. If the node inserted is changed to,
for
example:
<div class="message">
<b>Name</b>
<span>Hello World!</span>
</div>
Then all I would like to make as few changes as possible to my code. I
had hoped that
I could use some kind of document (XML, DTD, schema etc) to describe
the structure of
the node to be inserted. Subsequently, if the node structure changed,
it would
only be a matter of updating some kind of file, and the XHTML could be
parsed correlty.
Having researched this issue a little already, it seems that using
some kind of external
file / schema is not possible. However, it looks like JQuery may
help.
My question is, could I use JQuery to parse the XHTML fragment in a
manner which is
more loosely coupled than using DOM methods directly? If the XHTML
fragment was to change, then
I would like the changes to my code that parses it, to be as easy and
quick as possible.
One last note, when the XHTML fragment changes, the data wrapped in
the markup does not.
The JavaScript objects that model / store the data to be extracted
remain the same.
I hope I have made sense, and someone can help.
Many thanks,
Jack