cannot remove file after XercesDOMParser validation

"Bin Yan" <[email protected]>
Newsgroups gmane.text.xml.xerces-p.devel
Message-ID <OF3336C9AD.B1BDD1DC-ON85256E00.0066CDF0-85256E00.006762B7@health.state.ny.us>
Hi, All:

First mesg on this list.  Here is my problem. I have to user XML::Xerces
(2.3.0) to validate xml file against xsd. It works fine and generates
informative errors when validation failed. The problem is that I need to
remove the files after validation no matter if the validation passes or
fails. But with the following code, when falidation errors generated, the
XML file can never be unlinked. When validation is good, the file can be
removed. I think the file handler is never been released by the parser.
What am I missing here? Thanks.

Tony Yan

####

my $parser = XML::Xerces::XercesDOMParser->new();

eval {

$parser->setValidationScheme (1);
$parser->setDoNamespaces (1);
$parser->setCreateEntityReferenceNodes(1);
$parser->setDoSchema(1);
$parser->setExternalNoNamespaceSchemaLocation("sample.xsd");
$parser->setValidationSchemaFullChecking(1);


};
print $@ if $@;

my $error_handler = XML::Xerces::PerlErrorHandler->new();
$parser->setErrorHandler($error_handler);

###################### start to parse and/or validate #####################
my $xml_src;
eval {
  $xml_src = XML::Xerces::LocalFileInputSource->new("sample.xml");
  if ($xml_src) {
      $parser->parse ($xml_src);
  }

};
print $@ if $@;

############### clean up the files ############################
eval{
      $parser->reset();
      unlink("sample.xml") or print "cannot remove sample.xml";
      unlink("sample.xsd") or print "cannot remove sample.xsd";
};

print $@ if $@;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.