Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: extract tag form xml file

by Jenda (Abbot)
on Mar 20, 2019 at 15:28 UTC ( #1231498=note: print w/replies, xml ) Need Help??


in reply to extract tag form xml file

Just for future reference, here's a solution (proper one), that uses XML::Rules.

use strict; use warnings; use XML::Rules; my $rules =XML::Rules->new( style => 'parser', rules => { 'inline-formula' => sub { # (tag, attrs, context, parents, parser) open my $OUT, '>:utf8', $_[1]{id} . ".xml"; # open file na +med after the contents of the id attribute print $OUT $_[4]->toXML($_[0], $_[1]); # serialize the tag + with attributes close $OUT; }, '_default' => 'raw', # make sure we keep everything else intac +t } ); $rules->parse( *DATA ); __DATA__ <data> <inline-formula id="ieqn-1"><alternatives><mml:math display="inline">< +mml:mi>&#964;</mml:mi></mml:math></alternatives></inline-formula> <inline-formula id="ieqn-2"><alternatives><mml:math display="inline">< +mml:mi>&#964;</mml:mi></mml:math></alternatives></inline-formula> <inline-formula id="ieqn-3"><alternatives><mml:math display="inline">< +mml:mi>&#964;</mml:mi></mml:math></alternatives></inline-formula> </data>

Jenda
Enoch was right!
Enjoy the last years of Rome.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1231498]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2020-03-28 19:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    To "Disagree to disagree" means to:









    Results (167 votes). Check out past polls.

    Notices?