I have a theoretical grid of overlapping rectangles that might look something like this:

But all I need to work with is a collection of Rectangle objects:
var shapes = new List<Rectangle>(); shapes.Add(new Rectangle(10, 10, 580, 380)); shapes.Add(new Rectangle(15, 20, 555, 100)); shapes.Add(new Rectangle(35, 50, 40, 75));
What I would like to do is build a DOM-like structure, where each rectangle has a ChildRectangles property that contains the rectangles that are contained within it in the grid.
The end result should allow me to convert such a structure to XML, something like strings:
<grid> <shape rectangle="10, 10, 580, 380"> <shape rectangle="5, 10, 555, 100"> <shape rectangle="20, 30, 40, 75"/> </shape> </shape> <shape rectangle="etc..."/> </grid>
But basically it is the DOM-like structure in memory that I want, the XML output is just an example of how I can use such a structure.
The bit I'm stuck on is how to efficiently determine which rectangles belong.
NOTE No rectangles are partially contained inside another; they are always completely inside another.
EDIT Normally there will be hundreds of rectangles, do you just have to iterate over each rectangle to see if it contains another?
EDIT Someone suggested Contains (not my best moment, missed this!), But I'm not sure how best to build a DOM. For example, take the grandson of the first rectangle, the parent does contain a grandson, but he should not be a direct descendant, he must be a descendant of the parent's first child.