Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <tweets>
- <tweet>
- <content>hola, bonita </content>
- </tweet>
- <tweet>
- <content>hola, dictadura </content>
- </tweet>
- </tweets>
- my %hashcorpus = (
- dictadura => "nombre",
- bonita => "adjetivo", );
- #!/usr/bin/perl
- use warnings;
- use strict;
- use utf8;
- use XML::LibXML;
- my $filename = 'corpus.xml';
- my $dom = XML::LibXML->load_xml(location => $filename);
- foreach my $tweet ($tom->findnodes('//tweet'))
- {
- my @content = $tweet->findnodes('./content');
- die "<tweet> didn't have exactly one <content>: $tweet"
- unless @content==1;
- my $content = $content[0]->textContent;
- foreach my $key (keys %hash)
- {
- my $content =~ s/ $key / $hashcorpus{$key} /g;
- }
- $content[0]->removeChildNodes();
- $content[0]->appendText($content);
- #~ #say $content;
- }
- print $tom->toString;
Add Comment
Please, Sign In to add comment