Request - XmlElement::getParentElement


Maybe I’m missing something, but I cannot find a simple method in XmlElement that returns its parent node or zero if its the root element. This would be useful for some iterations. I think findParentElementOf does something else.


If i remember correctly, the XmlElement class doesn’t keep a pointer to its parent, so it wouldn’t just be a case of adding such a function; any existing functions that modify the structure would have to be modified to make sure such pointers weren’t left dangly.

Well, I guess that not dealing with parent pointers made it easier to implement the class. On the same note, there’s no getPreviousElement for siblings, either.

So the class is a kind of one-way referenced list (top-down and first-to-last only), which is okay and otherwise superb, but it would certainly be easier to use a flexible two-way class.

I was trying hard to keep the size of the xmlelements to a minimum, because if you read a big xml file, these things can get huge. There’s also all kinds of issues when you have parent pointer and start moving child elements between different parents, etc, and it slows it all down.

Besides, if an object has a pointer to a sub-element but no link to the top element of the tree, then it has no control over the lifetime of that sub-element pointer - and that sounds like a bug waiting to happen. A better way would be to give it a copy of the sub-element, plus any relevant info about the context in which it occurred.

Yes, of course, I can get around this by saving the pointers I need.

The class is fantastic BTW and makes handling xml data a breeze.