note
Jenda
<p>I have to repeat what the previous node already said, DO NOT TREAT XML FILES AS TEXT. Use a library that actually understands the format.</p>
<p>In this case one of the options is [CPAN://XML::Rules] in the filtering mode. You would read the CSV into a hash and then process the XML file with something like
<code>
use XML::Rules;
my $filter = XML::Rules->new(style => 'filter', rules => {
'XREF' => sub {
return $references{$_[1]->{_content}} ?? "Unknown reference $_[1]->{_content}";
}
});
$filter->filterfile($source_path, $result_path);
</code>
If you do not want to process all <XREF> tags, but only those within <LinkValue> you can change the code to something like this:
<code>
my $filter = XML::Rules->new(style => 'filter', rules => {
'XREF' => {
qr{/LinkValue$} => sub {
return $references{$_[1]->{_content}} ?? "Unknown reference $_[1]->{_content}";
}
# or
# qr{/Property/LinkValue$} => sub {
# return $references{$_[1]->{_content}} ?? "Unknown reference $_[1]->{_content}";
# }
# for only <Property><LinkValue><XREF>
}
});
</code>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-105128">
<p>Jenda<br>
<b>Enoch was right!</b><br/>
Enjoy the last years of Rome.
</p>
</div></div>
1208637
1208637