Nested XML

askrius

New member
Joined
Jan 26, 2009
Messages
1
Programming Experience
1-3
I have a nested XML page that I need to create objects represnting this relationship:

VB.NET:
<root>
    <item>
        <item_name>Test Item</item_name>
        <sub_items>
            <item>
                <item_name>Test Sub Item</item_name>
            </item>
            <item>
                <item_name>Test Sub Item 2</item_name>
                <sub_items>
                    <item>
                        <item_name>Sub Sub Item</item_name>
                    </item>
                </sub_items>
                <item>
                    <item_name>Test Sub Item 3</item_name>
                </item>
             </item>
	  </sub_items>
       </item>

        <item>
            <item_name>Test Item 2</item_name>
        </item>
</root>

The nesting could go beyond the 'sub sub item' level, though not more than 5 or 6 levels deep or so.

I need to create objects that contain collections of their 'sub items', etc...

can anyone point me to some documentation?

edit: I have no problem 'walking' the xml...I seems to be having a hard time with the creation of the objects and then linking them together...

edit2:

So, I have been looking at the Serialize/Deserialize method for a possible solution. This seems like it would work quite well for what i need. I can create an XSD from the XML...but only if I change my nested tag names (such as in the code tags below). From here I can create a class-set using that XSD. All that is well documented (MSDN). What I am wondering...is there a way to keep my nested "<item>" tags? I would like to allow recursive relationships between these objects...so an 'item' can have 'sub items' comprised of obejct type 'item' with some of these containing 'sub items', etc...perhaps there is a way to leverage XML tags that will let me do this thing...

VB.NET:
<root>
    <item>
        <item_name>Test Item</item_name>
        <sub_items>
            <item1>
                <item_name>Test Sub Item</item_name>
            </item1>
            <item1>
                <item_name>Test Sub Item 2</item_name>
                <sub_items1>
                    <item2>
                        <item_name>Sub Sub Item</item_name>
                    </item2>
                </sub_items1>
                <item1>
                    <item_name1>Test Sub Item 3</item_name1>
                </item1>
             </item>
	  </sub_items>
       </item>

        <item>
            <item_name>Test Item 2</item_name>
        </item>
</root>
 
Last edited:
Back
Top