Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XML
I am generating an HTML code using XML and C# winform. My XML looks like this:

<Groups>
<Group Name="Group1" ID="D7EBC5D6-0E6D-499E-B528-34BE14382755">
</Group>
<Group Name="Group2" ID="CC012258-14AC-44E9-BA0F-78AE7C569FCB" parent="D7EBC5D6-0E6D-499E-B528-34BE14382755">
</Group>
<Group Name="Group3" ID="E23D7E3B-9DDA-408E-9CC9-9AC1A9E36DD3" parent="D7EBC5D6-0E6D-499E-B528-34BE14382755">
</Group>
 
The Id of 'parent' element in lines 4 and 6 shows that these tags are the children of this ID(in this case the ID of group 1)
 
I have tried several different ways but they did not work. The XML must not be changed. How can I generate several nested group boxes in HTML?
Posted 10-May-13 23:34pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I am not sure what exactly you are trying to develop. As assumption is that you want to create nested HTML field set (which is normally used for grouping of elements) based on the lay out described on your xml.
 
You may construct an intermediate xml document object (temporarily) from the xml that you gaven here. It is pretty easy. Use some recursive function to traverse through all elements of the given layout xml and generate the modified xml as follows.
 
<Groups>
    <Group Name="Group1" ID="D7EBC5D6-0E6D-499E-B528-34BE14382755">
        <Group Name="Group2" ID="CC012258-14AC-44E9-BA0F-78AE7C569FCB"/>
        <Group Name="Group3" ID="E23D7E3B-9DDA-408E-9CC9-9AC1A9E36DD3"/>
    </Group>
</Groups>
 
Once this is done, you could construct the nested fieldset HTML easily.
 
<fieldset>
    <legend>Group1</legend>
    <fieldset>
        <legend>Group2</legend>
    </fieldset>
    <fieldset>
        <legend>Group3</legend>
    </fieldset>
</fieldset>
 
You may do some other customization if you want. Intermediate xml construction is not mandatory. You may directly construct the fieldset HTML from your lay out xml. But if you have to create this many times, then you may cache the intermediate xml.
 
Cheers,
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 11 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100