我在讀取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