in reply to XML::Twig approach/architecture/design question

Extracting regexps from the text of an element and tagging them is done using the mark method (in XML::Twig 3.00):

[Janitorial Note: In the following code, read XCODE as CODE. The original was messing up our <CODE> tags on certain browsers. --f ]

#!/bin/perl -w use strict; use XML::Twig; my $t= XML::Twig->new; $t->parse( \*DATA); # tag all matching strings with <a class="xcode">$1</xcode> # returns the list of newly created elements my @xref=$t->root->mark( qr/(@\w+)/, 'a', { class => 'xcode'}); foreach my $xref ( @xref) { $xref->set_content( substr( $xref->text, 1) ); # remove the lead +ing @ $xref->set_att( href => $xref->text . ".html"); } $t->print; __DATA__ <doc>text with a @reference to whichever @document I want</doc>

Actually I have a bunch of methods like this one, which are seldom used and hard to find in the docs and I was thinking of splitting them into a different module, XML::Twig::Utils or something similar. It would include the existing matk, split (similar to mark but returns a dufferent set f elements), and proably some more, plus methods that I use for conversions to XML, like merge, and break, and several others. Would this make sense?

Edit by footpad, Tue Nov 6 04:50:35 2001 (GMT).

Replies are listed 'Best First'.
Re: Re: XML::Twig approach/architecture/design question
by John M. Dlugosz (Monsignor) on Nov 06, 2001 at 01:15 UTC
    Whether you break it into another module or not, it does seem that you have a lot of specific detailed functions that help with exactly this kind of work, as well as the general access and manipulation tools.

    It just needs to be documented better. Whether moved into another module or not, separating the docs into "general" and "this kind of tool" is a good idea.

    —John