Re: XML::Rules tagspec

"Jenda Krynicky" <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
From: Terrence Brannon <[email protected]>
> Jenda Krynicky wrote:
> >> 2 -  but anyway I'm wondering why you cant select tags based on 
> >> attributes of the tag. And also why you cant provide a subref here that 
> >> returns true for tags matching its tests. In others, 
> >> HTML::Element::look_down can find tags by 'tagspec', but it can also 
> >> easily do various attribute tests and if that's not enough, use a sub ref.
> >>
> >> The reason I mention it, is that you could have two table tags in a 
> >> document and have different rules for processing each:
> >>
> >> sub my_table_1 {
> >>     $self->gi eq 'table' and $self->attr('table_number') == 1
> >> }
> >>
> >>  my $tagspec = \&my_table_1
> >>     
> >
> > I would like to keep it simple.
> This rules out XML::Rules for things like: "eliminate all sections 
> marked with attribute "klass" whose value is 12.
> 
> Processing XML (or in my case, XHTML) is not always based on the gi.
> 
> Whereas with treebuilder, I can do
> 
> my @node = $tree->look_down(klass => 12);
> $_->delete for @node;
> 
> if-then is my last resort for complexity management.

So you'd rather have a special restricted syntax, right? That let's 
you specify "I want all tags what have klass equal to 12", but breaks 
as soon as you want something like "klass equal to an even number" or 
"klass that matches this regexp" or ...

If by "section" you mean any tag then the code would look like this:

#!perl
use XML::Rules;

my $parser = XML::Rules->new(
	style => "filter",
	rules => {
		'^_default' => sub { ($_[1]->{klass} != 12) },
		# process only tags whose attribute klass != 12
	}
);

$parser->filter(\*DATA);

__DATA__
<root>
 <a klass="12">buhaha<blarg>x</blarg> sss</a>
 <a klass="13">buhaha<blarg>x</blarg><blarg>y</blarg> sss</a>
 <a>buhaha<blarg klass="12">x</blarg> sss</a>
</root>

----------------------------------------

Horribly complex is it?

And the good thing is that the content of the tags with klass="12" is 
never even stored in the memory and the attributes are forgotten 
immediately after the test.

I'd rather have one more more explicit if(){} than a more complex 
API. I don't have to learn if(){}s, I have to learn APIs.

But of course you are free to decide, nothing suits everyone.

Jenda
===== [email protected] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
	-- Terry Pratchett in Sourcery

_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.