
rovf
Veteran
Jan 9, 2012, 2:16 AM
Post #2 of 2
(3069 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.
|