Skip Menu |

This queue is for tickets about the XML-Rules CPAN distribution.

Report information
The Basics
Id: 75806
Status: resolved
Priority: 0/
Queue: XML-Rules

People
Owner: Nobody in particular
Requestors: DOUGW [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: 1.12



Subject: Pass only some tags
I'm wanting to pass only certain attributes to the parent hash, and I can do that longhand, but I'd like a shortcut. I have a patch to go after all the other 'pass ...' rules, not sure if the syntax should just be 'pass tag1,tag2' or 'pass attr tag1,tag2'. Here's code that does the former syntax: } elsif ($rule =~ /^pass\s+(\S+)$/) { my $tags = $1; @results = map { $_ => $data->{$_} } split /,/, $tags; Although the latter syntax might be better in case there's a tag named 'trim', in which case: } elsif ($rule =~ /^pass\s+attrs?\s+(\S+)$/) { my $tags = $1; @results = map { $_ => $data->{$_} } split /,/, $tags;
On Thu Mar 15 19:40:28 2012, DOUGW wrote: Show quoted text
> I'm wanting to pass only certain attributes to the parent hash, and I > can do that longhand, but I'd like a shortcut. I have a patch to go > after all the other 'pass ...' rules, not sure if the syntax should
just Show quoted text
> be 'pass tag1,tag2' or 'pass attr tag1,tag2'. Here's code that does
the Show quoted text
> former syntax: > > } elsif ($rule =~ /^pass\s+(\S+)$/) { > my $tags = $1; > @results = map { $_ => $data->{$_} } split /,/, $tags; > > Although the latter syntax might be better in case there's a tag named > 'trim', in which case: > > } elsif ($rule =~ /^pass\s+attrs?\s+(\S+)$/) { > my $tags = $1; > @results = map { $_ => $data->{$_} } split /,/, $tags; >
I'll probably use the first syntax, though the code will be a little different. This would not just filter the passed attributes, but also possibly introduce ones that were not in the XML in the first place. I have to think about this a bit more though because this would probably be handy not only for "pass" but also to "as is" and "as array" and maybe a few more so I should try to find a consistent way to specify the filtering. Jenda
On Thu Mar 15 19:40:28 2012, DOUGW wrote: Show quoted text
> I'm wanting to pass only certain attributes to the parent hash, and I > can do that longhand, but I'd like a shortcut. I have a patch to go > after all the other 'pass ...' rules, not sure if the syntax should
just Show quoted text
> be 'pass tag1,tag2' or 'pass attr tag1,tag2'. Here's code that does
the Show quoted text
> former syntax: > > } elsif ($rule =~ /^pass\s+(\S+)$/) { > my $tags = $1; > @results = map { $_ => $data->{$_} } split /,/, $tags; > > Although the latter syntax might be better in case there's a tag named > 'trim', in which case: > > } elsif ($rule =~ /^pass\s+attrs?\s+(\S+)$/) { > my $tags = $1; > @results = map { $_ => $data->{$_} } split /,/, $tags; >
I added remove(list,of,attributes) and only(list,of,attributes) as a "rule modifier". That is you can add it to (almost) any rule by just appending to the rule separated by a space: oneTag => 'as is remove(foo,bar,baz)', other => 'pass only(blah,bleh,bleargh)', I did not have time to write the tests for this, but the quick tests I run suggested that it works. I've also added support for parsing/filtering XML in chunks ... eg. to allow filtering huge XMLs downloaded by LWP::UserAgent. It's documented, but again no tests in the package yet. Let me know what you think please, Jenda
Subject: XML-Rules-1.11.tar.gz
Download XML-Rules-1.11.tar.gz
application/gzip 89.1k

Message body not shown because it is not plain text.

The only() and remove() filters are in the just released version 1.12.