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 Jeff Lewis <jd...@xactware.com> on 2000/07/13 15:54:41 UTC

RE: Reference to the object returned by getFirstChild and getNext Sibling???

You are actually getting a 'reference' or a 'smartpointer' to the node.  So
anything that you do to that reference, will take effect in any other
references to the same node:

DOM_Element root = doc.getDocumentElement();
DOM_Node child1 = root.getFirstChild();
DOM_Node refToChild1 = root.getFirstChild();

// Lazy casting only for example!!!  Don't do it this way!!!
((DOM_Element)refToChild).setAttribute("attr1","value1")

if (((DOM_Element)child).getAttribute("attr1").equals("value1")==TRUE)
{
	// We will get here!
}



-----Original Message-----
From: Anuj Seth [mailto:anuj@sasi.com]
Sent: Thursday, July 13, 2000 7:51 AM
To: xerces-c-dev@xml.apache.org
Subject: Reference to the object returned by getFirstChild and
getNextSibling???


Hi,

First, I'd like to thank Jeff Lewis and Joseph Kesselman. Their inputs
helped me a lot in writing a XML file merger application. There is just
this one problem that I'm facing and this is keeping me from actually
merging two documents!! :-(

During the DOM document traversal stage, I need to keep references to
certain nodes in the DOM_Document so that I can access them later and
manipulate them immediately. Unfortunately, the getFirstChild() and
getNextSibling() methods of DOM_Node return copies of the object and not
the actual object itself.

The implementation of getFirstChild() is,

DOM_Node DOM_Node::getFirstChild() const
{
    return DOM_Node(fImpl->getFirstChild());
};

As it can be seen, it is returning a copy of the object and not the
object itself. Is there any "replacement" functions for getFirstChild()
and getNextSibling() which returns "live" objects, i.e, the actual
object itself?

I was initially doing,

DOM_Node child = doc2.getFirstChild();

This results in a copy of the copy being created!

So, I changed it to,

DOM_Node &child = doc2.getFirstChild();

Even this does not help because getFirstChild returns a copy and not the
actual node. How can I get the reference to the actual node so that I
can store the reference and then use it later for manipulation?

I need this information very urgently. Any help will be greatly
appreciated.

I hope I've clearly explained the problem that I'm facing.

With Regards,
Anuj


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