我在读取XML文件时遇到问题。如果你看下面的xml,你会看到元素<fl> ?fl>
而不是<fl></fl>
。我收到错误打开和结束标记不匹配。解析器错误:开始和结束标记不匹配:
如何:
- 有在XML文件中,如
<fl> ?fl>
而不是<fl></fl>
的错误。如何忽略这样的错误,或者在读取xml时修复它们并将其用于解析? - 我只想读
$_->{desc}->[0]->{en}->[0]
的内容,而不是<de>
,<es>
,<fl>
。
现在我在读XML文件,如:
package test::test6382_sunseekingeurope;
use strict;
use warnings;
use test;
use base qw/test/;
use URI::URL;
use XML::Simple;
use Data::Dumper;
use constant TASK_ID => 6382;
use constant CR_TYPE => '6382';
use constant IMAGE_PATH => "/home/testco/public_html/files/";#"images/";
sub new
{
my $class = shift;
my $self = $class->SUPER::new(CR_TYPE, TASK_ID);
bless $self, $class;
my $url = 'http://www.onbip.com/xml/sunseeking9.xml';
my $xml = $self->geturl('url'=>$url);
$self->extract($xml);
}
sub extract{
my $self = shift;
my $xmlfile = shift;
my $xml = new XML::Simple(ForceArray=>1,'KeyAttr' =>'image');
my $data = $xml->XMLin($xmlfile);
foreach(@{$data->{property}}){
my $property = &makeScalar($_->ID->[0]);
my $description = &makeScalar($_->{desc}->[0]->{en}->[0]);
XML:
<property>
<id>226887</id>
<desc>
<en>
Nice house in the center of Alhaurin de la Torre with walking distance to all amenities.
</en>
<es>
Bonita casa mata en Alhaurin de la Torre con vistas a la montana, se puede acceder caminando al centro, colegios, etc.
</es>
<de>
guter zustand, bezaubernde immobilie,
</de>
<fl>
bon n acces par la route, partiellement meubl?a proximit?'?les, partiellement r?v
?fl>
</desc>
</property>
请,下次使用正确格式化。 – choroba
告诉你的代码不能读取XML,它只能通过Perl数据结构散步。我猜你是使用一个模块用于解析XML,但是你有什么显然不是XML ... – pmakholm