Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Hierarchical tag closing

by gugan (Initiate)
on Jan 06, 2012 at 05:16 UTC ( #946527=perlquestion: print w/replies, xml ) Need Help??
gugan has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks

I want close the tags in hierarchical way

E.g

This is my input

<P_Normal><list-bull></P_Normal> <P_list-bull(1)>Use Microsoft Windows accessibility </P_list-bull(1)> <P_list-simple(2)> Magnify the display </P_list-simple(2)> <P_list-simple(2)> Change the size of text and icons </P_list-simple +(2)> <P_list-simple(2)> Convert the text displayed </P_list-simple(2)> <P_list-simple(2)> Change the contrast </P_list-simple(2)> <P_list-simple(2)> Display an onscreen keyboard </P_list-simple(2)> <P_list-simple(2)> Convert the mouse for left-handed use. </P_list-s +imple(2)> <P_list-bull(1)>Deliver learning through </P_list-bull(1)> <P_list-bull(1)>Increase the character . </P_list-bull(1)> <P_list-bull(1)> fonts to assist dyslexic learners. </P_list-bull(1)> <P_list-bull(1)>Adjust background colours </P_list-bull(1)> <P_Normal></list-bull></P_Normal>

I want to close the list tags in hierarchical manner

<list list-type="bullet"> <list-item><p>Use Microsoft Windows accessibility options to: <list list-type="simple"> <list-item><p> Magnify the display</p></list-item> <list-item><p> Change the size of text and icons</p></list-item> <list-item><p> Convert the text displayed into speech (i.e. narrator)< +/p></list-item> <list-item><p> Change the contrast</p></list-item> <list-item><p> Display an onscreen keyboard</p></list-item> <list-item><p> Convert the mouse for left-handed use.</p></list-item> </list></p></list-item> <list-item><p>Deliver learning through </p></list-item> <list-item><p>Increase the character </p></list-item> <list-item><p> fonts to assist dyslexic learners.</p></list-item> <list-item><p> Adjust background colours</p></list-item> </list></p>

This is my first perl task

Help me and thank in advance

Replies are listed 'Best First'.
Re: Hierarchical tag closing
by roboticus (Chancellor) on Jan 06, 2012 at 11:42 UTC

    gugan:

    First use a parser (e.g. HTML::TreeBuilder, XML::Twig) to create a data structure (I'd suggest a hash of hashes, aka HoH) to represent the data. Then write a function to traverse your HoH and create a new HoH structured the way you like it. Finally, traverse your new HoH and emit the text.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://946527]
Approved by planetscape
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2016-09-27 04:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (494 votes). Check out past polls.