You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Lenny Hoffman <le...@earthlink.net> on 2002/05/08 02:23:15 UTC

Parsers and Document Factories

Hi All,

What do folks think about this idea:

Both the original DOM_Parser and IDOM_Parser were not only parsers, but
document factories as well.  We may want to change this.  I believe that
things become cleaner and more understandable when the factory function is
left up to the official factory, DOMImplementation, and the parser is merely
a utility for populating documents.

For example, instead of:

    DOMParser parser;
    Parser.parse(xmlFile);
    DOMDocument* doc = parser.getDocument();

This would be done:

    DOMDocument* doc =
       DOMDOMImplementation::getImplementation()->createDocument(…);
    DOMParser parser;
    Parser.parse(xmlFile, doc);
    ...
    delete doc;

This gets the parser out of the loop in deciding which document
implementation to use.  The parser does not care how the document is
created; it just knows how to populate it based on contents of an XML
source.  Also, perhaps more importantly, the parser also is not responsible
for maintaining the lifetime of documents, because it does not create them.
Thus, the parser is just another document client.

Usage is simplified because now there is no difference in responsibilities
for documents gained from an implementation for manual population, and for
populating with a parser.

    DOMDocument* doc =
       DOMDOMImplementation::getImplementation()->createDocument(…);
    ...
    // programmatically populate the document
    ...
    delete doc;

In both cases the user is responsible for deleting the document, instead of
the current situation with IDOM that they only do so if the document were
obtained from the DOMImplementation.

The only thing I could think for wanting to have the Parser create a
document is to ensure that it is completely empty, assuming that it makes no
sense to parse into a partially populated document.  But this could be
handled by the parser throwing
DOMException(DOMException::HIERARCHY_REQUEST_ERR,0) if the passed in
document were not empty.

Thanks,

Lenny


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