Title: DOM_Document and DOMParser are created before initializing xercess since I cannot create them using NEW

Hi
I am working with DOM input to create a XalanDocument. This is done by using the first part of usage pattern named "working with Dom input

and output" to create a XalanDocument. (written in the Xalan part)
This is done in an init method of a class I wrote (in c++).

// some of the members of my class
static DOMParser *_domParser;
static XercesParserLiaison * _parserLiaison;
DOM_Document * _domDocument;
XalanDocument * _xalanReelDoc;


// initiating the class members done in the constructor of my class
_domParser=new DOMParser();
_parserLiaison = new XercesParserLiaison();
_domDocument =new DOMDocument();

// init xalanDocument done in init method of my class
_domParser->parse( xmlfileSource);
*_domDocument= _domParser->getDocument();
_xalanRealDoc= _parserLiaison->createDocument(*_domDocument)

The difference between this and the Xalan usage pattern is that I use "new" to create the DOMParser,
XercesParserLiaison and DOMDocument.

I wrote a program that use this class and everything works.

but then I entered Xercess DOM programming guide and I read this:
"Never "new" a DOM object into the heap or make an ordinary C pointer
variable to one, as this will greatly confuse the automatic memory
management.

I sent the next 2 questions to the Xalan mailing list
way "newing" a DOM object do that ?
will I get an exception when this happened?
I have got this answer from Dave:

"You can create a DOM_Document instance with new, but you shouldn't.  It
will work, but it defeats the purpose of DOM_Document, which is a
smart-pointer to an underlying implementation instance.  If you do this,
you must make sure you _never_ make a copy of the pointer, which is a
difficult promise to keep.

It's best to ask questions related solely to Xerces on the Xerces-C list.

Dave"

but I still need to ask:
1. I call XMLPlatformUtils::Initialize in the constructor of my class
    if my DOMDocument member will be used like this DOMDocument _domDocument (and not with new )it means that when I create an object of my class then

    _domDocument constructor is called before the initialization of xerces. Is it OK?

2. I call XMLPlatformUtils::terminate in the distructor of my class. In case  my DOMDocument member will be used like this DOMDocument _domDocument it means

    that after the distruction of my class (which terminate xercess) the distructor of _domDocument is called. Is it OK?

3. The same two question with my DOMParser member In case I will create is like this DOMParser _domParser.

4. The DOMParser I use is static. In case I create more than one instance of my class the same DOMParser will be used ( I do not want to create it in every instance of my

    class) In init method of my class this static DOMParser parse method is called.
    Do I have to call DOMParser reset method before each call to DOMParser:parse method.(since it is a static member)?

hope some one can help
regards
Ifat
                                                                                                                              

[EMAIL PROTECTED]
Comverse Divisional Developer


Reply via email to