1$|=1;
2use XML::Rules;
3
4$xml = <<'*END*';
5<doc boo="789">
6 <person active="1">
7  <fname>Jane</fname>
8  <lname>Luser</lname>
9  <email>JLuser@bogus.com</email>
10  <address>
11   <street>Washington st.</street>
12   <city>Old Creek</city>
13   <country>The US</country>
14   <bogus>bleargh</bogus>
15  </address>
16 </person>
17 <person active="0">
18  <fname>John</fname>
19  <lname>Other</lname>
20  <email>JOther@silly.com</email>
21  <address>
22   <street>Grant's st.</street>
23   <city>New Creek</city>
24   <country>Canada</country>
25   <bogus>sdrysdfgtyh <foo>degtrhy werthy</foo> drthyu</bogus>
26  </address>
27 </person>
28</doc>
29*END*
30
31use Data::Dumper;
32%rules = (
33	_default => 'raw',
34	'^bogus' => undef, # means "ignore". The subtags ARE NOT processed.
35	'^person' => sub {
36		return $_[1]->{active};
37	},
38	person => sub {
39		if (not exists($_[3]->[-1]{':printed'})) {
40			print $_[4]->parentsToXML();
41			$_[3]->[-1]{':printed'} = 1;
42		}
43		print $_[4]->toXML($_[0], $_[1]), "\n";
44	},
45	doc => sub {
46		print "</doc>\n";
47	}, #'pass no content',
48);
49
50my $parser = new XML::Rules (
51	rules => \%rules,
52	# other options
53);
54
55my $result = $parser->parsestring($xml);
56