|Perl: the Markov chain saw|
HTML::TreeBuilder: sort a Definition List (<dl>)by svenXY (Deacon)
|on Sep 12, 2005 at 08:48 UTC||Need Help??|
svenXY has asked for the wisdom of the Perl Monks concerning the following question:
Enlightened Ones and other Seekers of Widsom,
For my wife, who is a software translator, I am trying to achieve the following:
I have a glossary in HTML, implemented as a definition list. After translation, the glossary naturally needs to be re-sorted.
I already wrote a solution with Regular Expressions but with HTML being hard to parse, it is not very efficient so far... Thus I'd like to use HTML::TreeBuilder
It's quite easy when the glossary was a two column table (check my scratchpad if you are interested: svenXY's scratchpad), but with a definition list, the problem is that the <dt> and the <dd> tag are independent of each other. I can well sort the dt tag, but how do I at the same time sort the dd tag with it?
My main problem is to properly dereference the tree and to replace the DL part of the tree with a sorted array of HTML::Element Objects without having to create and parse code first.
I have a solution here, but I don't really like it. I'm sure there are better ways to do it
Any hints greatly appreciated,