"Bin Yan" <[EMAIL PROTECTED]> writes:

> First mesg on this list.  

Welcome! I hope we can help you out.

> 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. 

Which platform are you using? I'm curious because this doesn't sound
like a Unix/Linux type issue.

> 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? 

Sounds very odd to me, but here would be what I would try:

1) scoping: place the parser in a different scope so that once parsing
   is complete, the interpreter is free to clean up the parser and all
   the memory/objects it contains.

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

    # do parsing stuff
  }

  unlink('foo.xml');
  unlink('foo.xsd');

2) try putting the unlink code in an END block. This will allow perl
   to also clean up any resources that may be open and blocking the
   file removal.

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

  # do parsing stuff

  END {
    unlink('foo.xml');
    unlink('foo.xsd');
  }


  
> ####

[snip]

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

The code looks fine, and I would expect this code to work fine under
linux - what output are you getting?

Just FYI, the reset() call doesn't really do anything - it just sends
a message to any handlers you've registered that they should release
any data they stored as a result of the parse, but since the only
handler you've registered is a PerlErrorHandler it doesn't store any
parse info.

Cheers,
jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to