Hi all,

I've modified DocumentImpl::importNode() to update the importing document's
map fNodeIDMap when importing nodes with ID attributes.
The only problem occurs if the importing document's DTD doesn't define the
imported attribute as an ID. Is there any way to check against that?
Here's the code:


NodeImpl *DocumentImpl::importNode(NodeImpl *source, bool deep)
{

// SNIPPETYSNIP

    case DOM_Node::ATTRIBUTE_NODE :
        {
            if (source->getLocalName() == null)
                newnode = createAttribute(source->getNodeName());
            else
                newnode = createAttributeNS(source->getNamespaceURI(),
                                        source->getNodeName());
        // if source is an AttrImpl from this very same implementation
        // avoid creating the child nodes if possible
//        if (source instanceof AttrImpl) {
            AttrImpl *attr = (AttrImpl *) source;
            if (attr->hasStringValue()) {
                AttrImpl *newattr = (AttrImpl *) newnode;
                newattr->setValue(attr->getValue());
                deep = false;
            }
            else {
                deep = true;
            }

                //
            // start importing ID
            // The imported attribute is an ID. Add it to the hashtable of
IDs
            //   that is constructed for use by GetElementByID().
            //
            AttrImpl *newattr = (AttrImpl *) newnode;
            if (attr->isIdAttr())
            {
                newattr->isIdAttr(true);

                if (fNodeIDMap == 0)
                    fNodeIDMap = new NodeIDMap(500);
                fNodeIDMap->add(newattr);
            }
                //
                // end importing ID
                //

//        }
//        else {
//            // Kids carry value
//            deep = true;
//        }
        }
        break;

// SNIPPETYSNIP

> -----Original Message-----
> From: Evert Haasdijk [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, April 24, 2001 13:26 PM
> To: [EMAIL PROTECTED]
> Subject: Losing ID's on importNode()
>
>
> Hi all,
>
> My application 'copies' part of an XML document into another (using
> DOM_Document::importNode()). Now, some of the imported DOM nodes
> have an ID,
> but I can't retrieve them after importing them (calling
> DOM_Document::getElementById()) because the document's fNodeIDMap isn't
> updated on importNode().
> Is there any way to update the ID map short of writing the new
> document and
> re-parsing it?
>
> TIA, Evert
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to