我正在尝试解析从外部源获取的 XML 文件,但由于文本节点中存在未编码的 XML 实体而遇到问题。
本质上,我问的是与this相同的问题,但针对的是 Perl 而不是 PHP。
<report>
<company>A & W</company>
<company>Some Other Company with a < in Inc.</company>
</report>
我尝试使用这样的东西:
my $readAllRecordsURI = "http://mycompany.com/CompanyOnline/GetRecord";
my @form_array = ("action" => "readAll", "table" => "QOPIDINF");
my $ua = LWP::UserAgent->new;
my $cics_request = (POST $readAllRecordsURI, \@form_array);
my $cics_response = $ua->request($cics_request);
my $xmlfile = $cics_response->content;
my $parser = XML::Parser->new( Handlers => {Char => \&handle_char});
$parser->parsefile( $xmlfile );
sub handle_char {
my ($p, $string) = @_;
#clean up text here...
}