Hai..
I have a file contains only opening tags. i have to put the corresponding closing tag for each opening tag.
i am facing problem with this more than 2 days..i couldnt reach to the proper output. so anyone please help
me to solve this..a small part of my file is
<section><head>Kinds of non-fiction texts</head>
<subsect1><head>The skills tested</head>
<subsect2><head>What to expect from the texts</head>
<subsect3><head>What is a non-fiction text?</head>
<subsect4><head>Analysing text types</head>
<subsect5><head>How to 'read' a non-fiction text</head>
<section><head>Kinds of non-fiction texts</head>
<subsect3><head>Allocating the exam time</head>
<subsect1><head>Purpose</head>
<subsect2><head>Audience</head>
<subsect1><head>Writinq about purpose and audience</head>
<subsect2><head>Analvsina a ranae of features</head>
<subsect3><head>Task</head>
<subsect1><head>Perspective and point of view</head>
<subsect1><head>Writer's perspective</head>
i need the output in below format
<section><head>Kinds of non-fiction texts</head>
<subsect1><head>The skills tested</head>
<subsect2><head>What to expect from the texts</head>
<subsect3><head>What is a non-fiction text?</head>
<subsect4><head>Analysing text types</head>
<subsect5><head>How to 'read' a non-fiction text</head>
</subsect5>
</subsect4>
</subsect3>
</subsect2>
</subsect1>
</section>
<section><head>Kinds of non-fiction texts</head>
<subsect3><head>Allocating the exam time</head>
</subsect3>
<subsect1><head>Purpose</head>
<subsect2><head>Audience</head>
</subsect2>
</subsect1>
<subsect1><head>Writinq about purpose and audience</head>
<subsect2><head>Analvsina a ranae of features</head>
<subsect3><head>Task</head>
</subsect3>
</subsect2>
</subsect1>
<subsect1><head>Perspective and point of view</head>
</subsect1>
<subsect1><head>Writer's perspective</head>
</subsect1>
</section>
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>
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.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
v-ambily
Member
155 Points
141 Posts
how to put closing tag according to each opening tag
Feb 22, 2012 03:31 AM|LINK
Hai..
I have a file contains only opening tags. i have to put the corresponding closing tag for each opening tag.
i am facing problem with this more than 2 days..i couldnt reach to the proper output. so anyone please help
me to solve this..a small part of my file is
<section><head>Kinds of non-fiction texts</head>
<subsect1><head>The skills tested</head>
<subsect2><head>What to expect from the texts</head>
<subsect3><head>What is a non-fiction text?</head>
<subsect4><head>Analysing text types</head>
<subsect5><head>How to 'read' a non-fiction text</head>
<section><head>Kinds of non-fiction texts</head>
<subsect3><head>Allocating the exam time</head>
<subsect1><head>Purpose</head>
<subsect2><head>Audience</head>
<subsect1><head>Writinq about purpose and audience</head>
<subsect2><head>Analvsina a ranae of features</head>
<subsect3><head>Task</head>
<subsect1><head>Perspective and point of view</head>
<subsect1><head>Writer's perspective</head>
i need the output in below format
<section><head>Kinds of non-fiction texts</head>
<subsect1><head>The skills tested</head>
<subsect2><head>What to expect from the texts</head>
<subsect3><head>What is a non-fiction text?</head>
<subsect4><head>Analysing text types</head>
<subsect5><head>How to 'read' a non-fiction text</head>
</subsect5>
</subsect4>
</subsect3>
</subsect2>
</subsect1>
</section>
<section><head>Kinds of non-fiction texts</head>
<subsect3><head>Allocating the exam time</head>
</subsect3>
<subsect1><head>Purpose</head>
<subsect2><head>Audience</head>
</subsect2>
</subsect1>
<subsect1><head>Writinq about purpose and audience</head>
<subsect2><head>Analvsina a ranae of features</head>
<subsect3><head>Task</head>
</subsect3>
</subsect2>
</subsect1>
<subsect1><head>Perspective and point of view</head>
</subsect1>
<subsect1><head>Writer's perspective</head>
</subsect1>
</section>
Thanks in advance
ignatandrei
All-Star
135047 Points
21654 Posts
Moderator
MVP
Re: how to put closing tag according to each opening tag
Feb 22, 2012 08:20 AM|LINK
HtmlAgility pack (Codeplex) will interpret this - and then you will just wrote the corresponding xml
v-ambily
Member
155 Points
141 Posts
Re: how to put closing tag according to each opening tag
Feb 22, 2012 10:14 AM|LINK
hi,
Please give me an idea to do this through c# coding
Thanks in advance
gerrylowry
All-Star
20515 Points
5713 Posts
Re: how to put closing tag according to each opening tag
Feb 22, 2012 03:27 PM|LINK
@ v-ambily
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 </section>.
(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.
<subsect1>
<subsect2>
<subsect3>
<subsect4>
<subsect5>
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>
<subsect3>
<subsect1> lower ... output </subsect3>
<subsect2>
<subsect1> lower ... output </subsect2>, </subsect1>
<subsect2>
<subsect3>
<subsect1> lower ... output </subsect3>, </subsect2>, </subsect1>
<subsect1> equal ... output </subsect1>
end of file ... output </subsect1>, </section>
g.
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.