Many thanks for the reply. However, I can't say this quite adds up for me. Here's a bit more info on the problem, and what I *think* you were suggesting. Any comments greatly appreciated.
What I want to do is: DOM_NodeList children = node.getChildList(); for (int i=0; i<children.getLength(); ++i) { DOM_Node child = children.item(i); if (child.getNodeType() == DOM_Node::ELEMENT_NODE) { DOM_Element element = castNodeToElement(child); // castNodeToElement how??? DOM_String s = element.getAttribute("attrName"); ..... } } Now we have (roughly) the following type structure: DOM_Element : public DOM_Node // smart-pointers ElementImpl : public NodeImpl // real nodes I can see that the following is valid (except for field access restrictions), because the node.fImpl is really an ElementImpl, even though node's fImpl pointer is typed as NodeImpl. DOM_Element element; element.fImpl = dynamic_cast<ElementImpl*> node.fImpl; // can't do this due to fImpl being nonpublic However, the "child" Node object I have is *really* a DOM_Node, *not* a DOM_Element being accessed by pointer-to-base-class. Therefore, it is *not* valid to cast this object. The following code (which I think is what you are suggesting) is valid only as long as a DOM_Element happens to have exactly the same bytewise memory layout as a DOM_Node. While this will in fact currently be the case, it is not guarunteed to be so (eg what if DOM_Element gets an extra member field in future..) DOM_Element element = *(reinterpret_cast<Element_Impl*> &child); Regards, Simon Kitching > -----Original Message----- > From: [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED] > Sent: Wednesday, January 05, 2000 2:07 AM > To: [EMAIL PROTECTED] > Subject: Re: comments on Xerces-c for HP-UX 10.20 pa-risc2.0 > (HP9000/800) > > > > > >Now for the request: > >I can't figure how to "cast" up the "hierarchy". > >In particular, I have a DOM_Node, which is of type ELEMENT_NODE. How do I > >build a DOM_Element referring to the same node?? > >Yes, I can use the DOM_Node methods, but would prefer to cast it and then > >use the more convenient DOM_Element methods.. > >Presumably I'm missing something very simple... > > > > It works in a Javaesque sort of way, via references. > > So its something like: > > DOM_Element asElem = (DOM_Element&)domNode; > > So you have a target element, which is by value because the DOM node types > are really just reference counted smart pointers that are always treated > by > value, and you cast the node to it by casting it as a reference to a > DOM_Element type. I believe this is correct, though I always have to > re-remember this when someone asks. > > ---------------------------------------- > Dean Roddey > Software Weenie > IBM Center for Java Technology - Silicon Valley > [EMAIL PROTECTED] >