You are viewing a plain text version of this content. The canonical link for it is here.
Posted to p-dev@xerces.apache.org by Ryan Dewell <rd...@regnow.com> on 2002/02/11 22:43:10 UTC

DOM Invalid w/o Parser Reference (segfault)

Hello,

I'm using v1.6 of XML::Xerces on Solaris 2.6.  In large projects, it's
particularly useful to be able to parse a document and then pass the DOM
around to other objects, functions, etc.  The problem with this is that the
DOM instance becomes useless once the parser object has been destroyed.

There may not be an elegant way around this, and of course the obvious fix
is to store a reference to the parser if you're going to be passing the DOM
around.  Another solution would be to pass the parser around instead of the
DOM.

I've included an example program which takes one parameter, the name of the
xml file to parse, and demonstrates that after the parser has been
destroyed, use of the DOM causes a segmentation fault.

Perhaps if the XML::Xerces::IDOM_Document could store its own reference of
the parser, and then set this to null in the DESTROY method?

Not a show stopper by any means, but an ability that was nice with
Expat/XML::DOM.  :)

Ryan Dewell


-------------------------------
#!/usr/local/bin/perl

use strict;
use XML::Xerces;

my $file = $ARGV[0];
my $dom = &parse($file);

if (defined $dom){
  print $dom->getDocumentElement->getNodeName() . "\n";
}

sub parse{
  my ($file) = @_;
  my $parser = XML::Xerces::IDOMParser->new();

  eval {
    $parser->parse (XML::Xerces::LocalFileInputSource->new($file));
  };

  if ($@) {
    if (ref $@) {
      die $@->getMessage();
    } else {
      die $@;
    }
  } else {
    return $parser->getDocument();
  }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: DOM Invalid w/o Parser Reference (segfault)

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Jason E. Stewart" <ja...@openinformatics.com> writes:

> It is supposed to work this way (as documented by Xerces-C,
> anyway). They claim that all memory is associated with the *Document*
> and not the parser, therefore deleting the parser shouldn't free up
> the memory for the document, but it is.

Ok, I was wrong. I just checked the Xerces-C docs, and sure enough,
the memory is freed when the parser object goes out of scope. 

You're correct in that the quick fix would be for the IDOM_Document to
hold a reference to it's parser object. Perhaps that's the only fix.

I'll have to think about this one.

Thanks,
jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: DOM Invalid w/o Parser Reference (segfault)

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Ryan Dewell" <rd...@regnow.com> writes:

> I'm using v1.6 of XML::Xerces on Solaris 2.6.  In large projects,
> it's particularly useful to be able to parse a document and then
> pass the DOM around to other objects, functions, etc.  The problem
> with this is that the DOM instance becomes useless once the parser
> object has been destroyed.

Ahhh!!! 

This shouldn't be happening, but I've checked it and you're correct,
memory is getting freed that shouldn't.

> There may not be an elegant way around this, and of course the obvious fix
> is to store a reference to the parser if you're going to be passing the DOM
> around.  Another solution would be to pass the parser around instead of the
> DOM.

Passing around the parser would work, for now. But I should fix this.

> Not a show stopper by any means, but an ability that was nice with
> Expat/XML::DOM.  :)

It is supposed to work this way (as documented by Xerces-C,
anyway). They claim that all memory is associated with the *Document*
and not the parser, therefore deleting the parser shouldn't free up
the memory for the document, but it is.

Thanks,
jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: DOM Invalid w/o Parser Reference (segfault)

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Ryan Dewell" <rd...@regnow.com> writes:

> Perhaps if the XML::Xerces::IDOM_Document could store its own
> reference of the parser, and then set this to null in the DESTROY
> method?

I've looked into other methods, and I don't think I can solve the
memory issues. I think this might be the only way to make it work.

> Not a show stopper by any means, but an ability that was nice with
> Expat/XML::DOM.  :)

I'll let you know what I find.
jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org