Tim Bray wrote:
>At 12:14 PM 11/18/99 -0700, Tom Palmer wrote:
>>Still, what if someone wanted to use one organization's parser
>>and another's DOM implementation?  These should be kept
>>independent if at all possible.
>
>Errr, how is that possible?  The way things normally work is, parser
>reads XML resource, loads it into data structure, offers DOM API to it.
>The parser and DOM implementation are necessarily somewhat in bed, unless
>we want to require DOM implementations to use SAX to build it.  Do we?
-T.

The C++ DOM parser populates the DOM using plain vanilla DOM calls
whenever they are available.

Here's a code snippit from the DOM parser code that handles
a StartElement event (from an document handler interface that
is similar in flavor to SAX).  createElement(), setAttribute()
and appendChild() do the work of building the DOM tree.

{
    DOM_Element elem = fDocument.createElement(elemDecl.getFullName());
    for (unsigned int index = 0; index < attrCount; index++)
    {
        const XMLAttr* oneAttrib = attrList.elementAt(index);
        elem.setAttribute(oneAttrib->getName(), oneAttrib->getValue());
    }

    fCurrentParent.appendChild(elem);
    fNodeStack->push(fCurrentParent);
    fCurrentParent = elem;
    fCurrentNode = elem;
    fWithinElement = true;

    // If any empty element, do end right now (no endElement() will be
called)
    if (isEmpty)
        endElement(elemDecl, isRoot, startSrcOfs, endSrcOfs);
}

  -- Andy Heninger


Reply via email to