At 17.03 29/03/2005 +0400, Michael Kochetkov wrote:
> >BTW, I have noticed that
> >for (XMLSize_t i = 0; i < len; ++i) {
> >         XS::DOMNode* curNode = myNodes->item(i);
> >         XS::DOMElement* curElement =
> >reinterpret_cast<XS::DOMElement*>(curNode);
> >         XS::DOMNodeList *anotherNodeList =
> >elem.getElementsByTagName(wsAgent.c_str());
> >
> >works pretty well indeed even if curNode does not contain
> child nodes
> >(XS stands for the Xerces long namespace name). Does Xerces
> ever return
> >pure
> >DOMNode* pointers?
>
> I don't get the issue: what do you mean by "works pretty well
> indeed"? I cannot even guess what this code should do, as you
It does not crash.

Why should it? you are not using curElement, but an "elem" object that I don't know where it comes from.



> are invoking getElementsByTagName on the "elem" variable but
> you just initialized "curElement".
> As for the "pure DOMNode* pointers", I guess you are asking
> if a DOMNode object can ever exist; in this case, the answer
> is no, as it is a pure virtual interface.
Well, I do not know the Xerces internals, so I will try to elaborate my
question. I was going to use dynamic_cast to be sure the pointer
myNodes->item(i) returns has getElementsByTagName method. As far as DOMNode
itself does not have getElementsByTagName and the "blind" cast is used in
original Xerces example there is a chance that such downcasting may stop
working in the future. A misbehavior may be caused with multiple
inheritance, for example. As far as I am not a Xerces expert but I believe I
know programming in C++ :) so while studying examples I begin to think about
some non-language conventions. Such a convention may be the prohibition of
multiple inheritence, definite class order in multiple inheritence or
item(i) always return DOMElements, etc. So, I just want to be sure the
DOMElement* elem = (DOMElement*)elems->item(i); is reliable and will remain
to be reliable in the future.

You can be sure that myNodes->item() call will always return DOMElement object if it is the return value of a getElementsByTagName. But if it has been returned by a call to getChildNodes it will contains DOMText, DOMComment, etc...
The correct programming would be checking for getNodeType to be equal to ELEMENT_NODE before casting to a DOMElement.


Alberto



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



Reply via email to