Click here to Skip to main content
15,891,852 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am generating an HTML code using XML and C# winform. My XML looks like this:

XML
<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

1 solution

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.

XML
<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.

XML
<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,
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900