The C++ way of doing this is the following code fragment:

if(node.getNodeType() == DOM_Node::ELEMENT_NODE) {
  DOM_Element element = static_cast<DOM_Element&>(node);
}


John Snelson

"Arnold, Curt" wrote:
> 
> A very common pattern (at least in my code) when using Xerces-J's DOM is to do 
>something like:
> 
> for(DOM_Node node = element.getFirstChild();
>     node != null;
>     node = node.getNextSibling()) {
>     if(node.getNodeType() == DOM_Node.ELEMENT_NODE) {
>         DOM_Element childElem = (DOM_Element) node;
>         //
>         //  do some element specific behavior
> 
> I haven't found a good way to do the equivalent of:
> 
>         DOM_Element childElem = (DOM_Element) node;
> 
> with Xerces-C.  I think you could do somehting like:
> 
>         DOM_Element childElem = *((DOM_Element*) &node);
> 
> but that seems pretty ugly and may be fatal if you didn't do the preliminary check 
>for getNodeType() == ELEMENT_NODE.
> 
> What I was thinking was that adding a constructor for DOM_Element that took a 
>DOM_Node& and would throw an exception if the node wasn't appropriate would allow you 
>to keep the Java pattern.  (Of
> course, you would want to do this for all the other DOM_Comment, 
>DOM_ProcessingInstruction, et al).
> 
> Maybe this could go into the new DOM implementation?

-- 
John Snelson, Software Engineer       DecisionSoft Ltd.
Telephone: +44-1865-203192            http://www.decisionsoft.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to