CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Regular Expressions:
List tag closing in hierarchical way


New User

Jan 6, 2012, 5:56 PM

Post #1 of 2 (3747 views)
List tag closing in hierarchical way Can't Post

Hi guru's

i'm very newer to Perl,i need all ur's help to complete my task.
i want to close the list tags in hierarchical manner,there may any numbers of inner list tags in different listing styles
for e.g

<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
<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
<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)>

and my result should be generate like the below code

<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-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>

pls any one suggest me an idea to solve my problem
thank u


Jan 9, 2012, 2:16 AM

Post #2 of 2 (3684 views)
Re: [mahalakshmi] List tag closing in hierarchical way [In reply to] Can't Post

First, I think you made a mistake when posting the desired result, because it is not well-formed (there is one </list-item> missing).
Please correct this, so that we can understand your problem better.

If I understand you correctly, your input data (<P_Normal>...) is XML, and the result is also XML. Since nested structures are difficult to deal with using regular expressions, I suggest a different approach: To parse the XML code and generate new XML.

You could do this with XML::Simple from CPAN (which can do reading and writing), or with XML::Parser and XML::Writer. I personally worked only with XML::Simple, but this module has its limitations, and many experienced developers recommend XML::Parser instead. Maye you can try both and see what is better suited for you.

In both cases, the XML structure will be transformed into a hash, where the XML tags end up as hash keys. You would then transform this "hash tree" (by replacing the old tags by new ones) and then write the XML tree.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives