Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Keep It Simple, Stupid
 
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

Comment on Hierarchical tag closing
Select or Download Code
Re: Hierarchical tag closing
by roboticus (Canon) 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 surveying the Monastery: (4)
As of 2014-04-21 03:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (490 votes), past polls