Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Feb 22, 2012 03:27 PM|LINK
i'm guessing that you already know how to write the c# ... you simply need a strategy ...
i'm assuming that each line you've shown us starts on a new line.
as per on your example, in pseudo-code, a strategy like this should work:
(a) your first line is an exception ... just read it and save it
(b) create a List<string> secitons
(c) every time you get a <subsectn> add it to your list ...
(c) every time you get a <seciton> tag, reverse process your list, that output
(d) at end of file, reverse process your list, that output </section>.
note: when you reverse process your list, delete each entry so that your list is empty as you begin processing a new section.
The above strategy works for your first group.
For the second group, you would need to refine your strategy:
if you encounter a <subsectn> where n is less than or equal to the previos subsection ... you would need to:
-- clear your list BUT
-- NOT output </section>
<subsect1> lower ... output </subsect3>
<subsect1> lower ... output </subsect2>, </subsect1>
<subsect1> lower ... output </subsect3>, </subsect2>, </subsect1>
<subsect1> equal ... output </subsect1>
end of file ... output </subsect1>, </section>
edit: you obviously have to output each line you read ... if there is no need to write an end tag, just output the line read ... when there is a need to write one or more end tag(s), write them and then output the line just read ... at
end of file, write the line just read before your end tags.