Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: extract tag form xml file

by Jenda (Abbot)
on Mar 20, 2019 at 15:28 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1231498]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-18 08:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found