私はxmlファイルと、xmlファイルを置き換えるためのいくつかの置き換えチェックリストを持っています。正規表現をエスケープしてそのxmlファイルを置き換えるにはどうすればよいですか。そのコンセプトを試してみましたが、完全には機能しません...どうすればこれを行うことができますか?
私は試した:
入力 XML:
<xml>
<p class="text">The <em type="italic">end</em> of the text</p>
<p class="text">The <bold type="strong">end of the</bold> text</p>
<p class="text">The end of <samll type="caps">the<small> text</p>
</xml>
脚本:
use strict;
open(IN, "xml_file.xml") || die "can't open $!";
my $text = join '', <IN>;
my @ar = '';
my $testing;
foreach my $t (<DATA>){
@ar = split /\t/, $t;
chomp($ar[0]);
chomp($ar[1]);
$text =~ s/$ar[0]/$ar[1]/segi;
}
print $text;
__END__
<p([^>]+)?> <line>
<small([^>]+)?> <sc$1>
<bold type=\"([^"]+)\"> <strong act=\"$1\">
<(\/)?em([^>]+)?> <$1emhasis$2>
出力が必要です:
<xml>
<line>The <emhasis type="italic">end</emhasis> of the text</line>
<line>The <strong act="strong">end of the</strong> text</line>
<line>The end of <sc type="caps">the<sc> text</line>
</xml>
このタグの正規表現をチェックリストとして置き換える方法と、グループパターンから値を取得する方法..