[jQuery] converting HTML to XML using jQuery

[jQuery] converting HTML to XML using jQuery


I have been struggling with trying to do the following... perhaps I am
looking at it "too" hard since I have a feeling the solution is right
in front of me (i hope).
I have something like the following:
<div class="map">
<div class="title">Title</div>
<div class="group">
Group Name 1
<div class="group">Group Name 1-1</div>
</div>
<div class="group">
Group Name 2
<div class="group">Group Name 2-1</div>
</div>
</div>
I would like to turn this into XML, like:
<map>
<title>Title</title>
<group>Group Name 1
<group>Group Name 1-1</group>
</group>
<group>Group Name 2
<group>Group Name 2-1</group>
</group>
</map>
I have been trying using the .each() function but it doesn't seem to
hold the context node (when my context is the .map node and I want to
iterate the .group, it will iterate ALL of them, instead of the TWO
directly under the .map element. I can brute force this with some
recursion but I thought there must be a way to retain the context of
the jQuery.
Perhaps the .each way isn't the right approach?
Thanks in advance.