Venkateswar Bhamidipati wrote: > > hi all, > I want to convert a DOM_Node to a DOM_Element > and assign it to a DOM_Element...how can I do that ? > > DOM_NodeList messageNodes = > accountElement.getElementsByTagName(MESSAGE_TAG); > for(int i=0; i<messageNodes.getLength();++i) > { > DOM_Element messageElement = messageNodes.item(i); > } > > how do I type cast it or is there any funtion for that conversion???
Err, this is C++, right? This should work: DOM_Node tmp_node = messageNodes.item(i); DOM_Element messageElement = static_cast<DOM_Element&>(tmp_node); I've tried this without using the tmp_node step (i.e. just a static_cast on the return value from item()) but the compiler barfed on it. I ended up creating a function to do this because it was happening so much, i.e. DOM_Element getFromNodeList(DOM_NodeList& n, unsigned int which) { DOM_Node tmp_node = n.item(which); DOM_Element result = static_cast<DOM_Element&>(tmp_node); return result; } And then I trust the compiler to inline and optimise this function appropriately. If it's not performance critical this approach will definitely work, but someone else may have a better solution. Best regards, Mike. -- Mike Mason, Software Engineer XML Script Development Team Office: 44-1865-203192 http://www.xmlscript.org/ Mobile: 44-7050-288923