Hi experts,

I've problem in multilevel tag closing,i want to close the tags form the inner level then come to close its outer level

e.g

<P_Normal><list-bull></P_Normal> <P_list-bull(1)>Use Microsoft Windows accessibility options to: </P_li +st-bull(1)> <P_list-simple(2)>&#x2013; Magnify the display </P_list-simple(2)> <P_list-simple(2)>&#x2013; Change the size of text and icons </P_lis +t-simple(2)> <P_list-simple(2)>&#x2013; Convert the text displayed into speech &# +x0028;i.e. narrator&#x0029; </P_list-simple(2)> <P_list-simple(2)>&#x2013; Change the contrast </P_list-simple(2)> <P_list-simple(2)>&#x2013; Display an onscreen keyboard </P_list-sim +ple(2)> <P_list-simple(2)>&#x2013; Convert the mouse for left-handed use. </ +P_list-simple(2)> <P_list-bull(1)>Deliver learning through an audio podcast rather than +written handouts for visually impaired learners. </P_list-bull(1)> <P_list-bull(1)>Increase the character size on handouts for visually i +mpaired learners. </P_list-bull(1)> <P_list-bull(1)>Adjust background colours and fonts to assist dyslexic + learners. </P_list-bull(1)> <P_list-bull(1)>&#x003C;pg&#x003E;13&#x003C;/pg&#x003E;Provide feedbac +k on written work using the comments facility and track changes rathe +r than handwritten notes, so that the learners can change character s +ize or use a text to speech application to hear feedback.</P_list-bul +l(1)> </list-bull>

my output should be like the below code

<list list-type="bullet"> <list-item><p>Use Microsoft Windows accessibility options to: <list list-type="simple"> <list-item><p>&#x2013; Magnify the display</p></list-item> <list-item><p>&#x2013; Change the size of text and icons</p></list-ite +m> <list-item><p>&#x2013; Convert the text displayed into speech (i.e. na +rrator)</p></list-item> <list-item><p>&#x2013; Change the contrast</p></list-item> <list-item><p>&#x2013; Display an onscreen keyboard</p></list-item> <list-item><p>&#x2013; Convert the mouse for left-handed use.</p></lis +t-item> </list></p></list-item> <list-item><p>Deliver learning through an audio podcast rather than wr +itten handouts for visually impaired learners.</p></list-item> <list-item><p>Increase the character size on handouts for visually imp +aired learners.</p></list-item> <list-item><p>Adjust background colours and fonts to assist dyslexic l +earners.</p></list-item> <list-item><p><xref ref-type="page" id="page_13"/>Provide feedback on +written work using the comments facility and track changes rather tha +n handwritten notes, so that the learners can change character size o +r use a text to speech application to hear feedback.</p></list-item> </list>

i tried the below code but i gives single item list only i d't know where its wrong pls correct my mistake monk's

use strict; my $inputfile = $ARGV[0]; open (IN,"$inputfile") || die ("Can't open the input file for reading" +); undef $/; my $str = <IN>; while($str =~ /<list-(bull)>(?:(?:(?!<\/list-bull>).)*)<\/list-\1>/sg +i) { $str =~ s#<list-(bull)>(?:(?:(?!<\/list-bull>).)*)<\/list-\1>#&Lis +t_find($&)#sgie; } sub List_find { my $line = @_[0]; my $currentlevel = 0; while($line =~ /^[\s\S]*?<(P_list-(\w+)\((\d+)\))>(.*?)<\/\1>\s*/si) { my ($tag, $kind, $level, $text) = ($1, $2, $3, $4); if ($currentlevel < $level) { while($currentlevel < $level) { $line = "\n<list list-type=\"$kind\">\n<list-item><p>"; $currentlevel++; } } elsif ($currentlevel > $level) { while($currentlevel > $level) { $currentlevel--; $line ="</p></list-item>\n</list>\n"; } $line = "</p></list-item>\n<list-item><p>"; } else { $line = "</p></list-item>\n<list-item><p>"; } $line .= $text; # print $line; } while($currentlevel > 0) { $currentlevel--; $line .= "</p></list-item>\n</list>\n"; } #print $line; return "$line"; } open (OUT,">$inputfile\.xml") || die ("Can't open the output file for +writing"); print OUT $str; close (OUT);

pls consider my problem


In reply to Multilevel tag closing by maha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.