You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Ori Doolman <Or...@SigValue.com> on 2006/08/20 23:47:19 UTC

why does DOMBuilderImpl::loadGrammar releases my DOMDocument?

Hello,

I'm parsing xml files using Xerces-c 2.7 DOM.

I do the following things (more or less):

 

1.	create a XMLGrammarPoolImpl object and then create a new
DOMBuilder using it as an input.
2.	parse an xml file using the DOMBuilder and keep a reference to
the DOMDocument, 'doc1'
3.	parse another XML file using the same DOMBuilder and keep a
reference to the DOMDocument 'doc2'
4.	Create a new DOMInputSource and call DOMBuilder
->loadGrammar(inputSrc, SchemaGrammarType, true)

 

The result is that my previous parsed document, 'doc2' is being released
by the following code in parsers\DOMBuilderImpl.cpp on
DOMBuilderImpl::loadGrammar  (line 703):

 

        // Release DOM tree - DTD

        DOMDocument* doc = adoptDocument();

        if (doc)

            doc->release();

 

 

Can someone explain why my document is being release and how to overcome
that? Is it a bug?

 

Thank you,

Ori.


Re: why does DOMBuilderImpl::loadGrammar releases my DOMDocument?

Posted by 4p...@sneakemail.com.
The DOM parser actually owns the document you parsed. If you want to 
hold more than one document in memory, create more than one parser 
instance, because each will only hold one document instance.

Cheers,

Uwe

Ori Doolman OriD-at-SigValue.com |xerces-c-users mailing list| schrieb:
> Hello,
>
> I'm parsing xml files using Xerces-c 2.7 DOM.
>
> I do the following things (more or less):
>
>  
>
> 1.	create a XMLGrammarPoolImpl object and then create a new
> DOMBuilder using it as an input.
> 2.	parse an xml file using the DOMBuilder and keep a reference to
> the DOMDocument, 'doc1'
> 3.	parse another XML file using the same DOMBuilder and keep a
> reference to the DOMDocument 'doc2'
> 4.	Create a new DOMInputSource and call DOMBuilder
> ->loadGrammar(inputSrc, SchemaGrammarType, true)
>
>  
>
> The result is that my previous parsed document, 'doc2' is being released
> by the following code in parsers\DOMBuilderImpl.cpp on
> DOMBuilderImpl::loadGrammar  (line 703):
>
>  
>
>         // Release DOM tree - DTD
>
>         DOMDocument* doc = adoptDocument();
>
>         if (doc)
>
>             doc->release();
>
>  
>
>  
>
> Can someone explain why my document is being release and how to overcome
> that? Is it a bug?
>
>  
>
> Thank you,
>
> Ori.
>
>
>   


Re: why does DOMBuilderImpl::loadGrammar releases my DOMDocument?

Posted by Axel Weiß <aw...@informatik.hu-berlin.de>.
Ori Doolman wrote:
> Hello,
>
> I'm parsing xml files using Xerces-c 2.7 DOM.
>
> I do the following things (more or less):
>
>
>
> 1.	create a XMLGrammarPoolImpl object and then create a new
> DOMBuilder using it as an input.
> 2.	parse an xml file using the DOMBuilder and keep a reference to
> the DOMDocument, 'doc1'
> 3.	parse another XML file using the same DOMBuilder and keep a
> reference to the DOMDocument 'doc2'
> 4.	Create a new DOMInputSource and call DOMBuilder
> ->loadGrammar(inputSrc, SchemaGrammarType, true)
>
>
>
> The result is that my previous parsed document, 'doc2' is being released
> by the following code in parsers\DOMBuilderImpl.cpp on
> DOMBuilderImpl::loadGrammar  (line 703):
>
>
>
>         // Release DOM tree - DTD
>
>         DOMDocument* doc = adoptDocument();
>
>         if (doc)
>
>             doc->release();
>
>
>
>
>
> Can someone explain why my document is being release and how to overcome
> that? Is it a bug?

Ori,

AFAIK you can call adoptDocument() yourself and release the doc after use.

HTH,
			Axel