After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 351876 - Implement Node::get_parent()
Implement Node::get_parent()
Status: RESOLVED FIXED
Product: libxml++
Classification: Bindings
Component: General
2.14.x
Other All
: Normal minor
: ---
Assigned To: Stef Walter
Christophe de Vienne
Depends on:
Blocks:
 
 
Reported: 2006-08-18 04:02 UTC by Stef Walter
Modified: 2006-11-17 15:35 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Implements missing method. (1.26 KB, patch)
2006-08-18 04:02 UTC, Stef Walter
none Details | Review
Patch with constness, get_xxx_sibling (3.33 KB, patch)
2006-10-25 15:40 UTC, Stef Walter
committed Details | Review
Tests new functionality (852 bytes, text/plain)
2006-10-25 15:41 UTC, Stef Walter
  Details

Description Stef Walter 2006-08-18 04:02:09 UTC
Currently there's no way to retrieve the parent element for a node in the DOM. Attached is a patch that implements the method: 

Element* Node::get_parent()
Comment 1 Stef Walter 2006-08-18 04:02:59 UTC
Created attachment 71123 [details] [review]
Implements missing method.
Comment 2 Murray Cumming 2006-08-18 06:23:32 UTC
Thanks. It looks good to me, though it probably needs both a const and unconst version:

const Element* get_parent() const; 
Element* get_parent();

and a ChangeLog entry.

Then it should be comitted to HEAD after we have created a gnome-2-16 branch. 
Comment 3 Eric Beyeler 2006-10-12 17:48:25 UTC
I would say get_next_sibling and get_previous_sibling would be good to have as well
Comment 4 Stef Walter 2006-10-25 15:39:42 UTC
I don't see a gnome-2-16 branch yet, but I'll attach my final patches and test program. 
Comment 5 Stef Walter 2006-10-25 15:40:57 UTC
Created attachment 75377 [details] [review]
Patch with constness, get_xxx_sibling
Comment 6 Stef Walter 2006-10-25 15:41:39 UTC
Created attachment 75378 [details]
Tests new functionality
Comment 7 Murray Cumming 2006-11-10 23:43:51 UTC
This seems to be accessing the struct members directly. Is there any libxml documentation that says that this is a legitimate thing to do?

Even if it is, I would rather not add the sibling stuff. We already have a way to list the children of a node.
Comment 8 Stef Walter 2006-11-11 20:55:21 UTC
Yes, accessing the struct members directly is how you walk a tree in libxml:

http://xmlsoft.org/examples/tree1.c
http://xmlsoft.org/examples/tree2.c

And this is how libxml++ currently works (couldn't work without it).
Comment 9 Stef Walter 2006-11-11 21:04:04 UTC
Committed Node::get_parent(). 

As far as the sibling stuff, it really does make a difference when implementing many XML algorithms. In DOM, using Node.firstChild, Node.lastChild, Node.nextSibling, Node.previousSibling and Node.parent together allow you to do many things that would otherwise be unwieldly or overly complicated. This is especially true when dealing with 'document' oriented XML. 

I'm the author of RTFX and made heavy use of these methods when writing it:

http://memberwebs.com/nielsen/software/rtfx/

Comment 10 Murray Cumming 2006-11-17 08:06:03 UTC
OK. Please go ahead. Thanks for convincing me.

For the const overloads, you might want to do 
  return const_cast<Node*>(this)->the_method();
just to reduce the library size slightly, though we probably don't do that elsewhere  yet, and the copy/pasted implementation is small.
Comment 11 Stef Walter 2006-11-17 15:35:18 UTC
Thanks. Done.