‎2011 Apr 15 2:38 PM
Hi,
In the [documentation of iXML library|http://help.sap.com/saphelp_nw70/helpdata/en/86/8280d812d511d5991b00508b6b8b11/frameset.htm] there is a part about casting down the objects.
It says that using ?= operator is not enough and query_interface should be used instead:
quote:
"data: node type ref to if_ixml_node,
element type ref to if_ixml_element.
...
element ?= node->query_interface ( ixml_iid_element ).
For each interface in the iXML library there is one constant ixml_iid_... that can be used with query_interface(). Be aware to use the dynamic cast operator ?=, using = is not sufficient. "
Does anyone know what does it mean "is not sufficient"?
I'm using ?= operator to cast node to element and it works fine. No exceptions are thrown and I can access all the attributes and methods of the element.
DATA iterator TYPE REF TO if_ixml_node_iterator.
DATA elem TYPE REF TO if_ixml_element.
iterator = xmldoc->get_elements_by_tag_name( 'cell' )->create_iterator( ).
elem ?= iterator->get_next( ).Is there something I'm not aware of that could fail when using ?= directly?
‎2011 Apr 18 1:27 AM
Hi,
it looks like interoperability issue. It's mentioned in doco linked by you.
You may now ask yourself why this works only when casting up and why you have to explicitly cast your way down the inheritance hierarchy? Well, this again is due to the fact how the iXML ABAP Objects wrappers interact with their C++ counterparts in the kernel. Believe me, there is no efficient way around this problem, except if the ABAP Objects language would be extended to allow operator overloading; I could then overload the cast (?=) operator to call query_interface() internally. But this is unlikely to happen.
Cheers
‎2011 Apr 18 1:27 AM
Hi,
it looks like interoperability issue. It's mentioned in doco linked by you.
You may now ask yourself why this works only when casting up and why you have to explicitly cast your way down the inheritance hierarchy? Well, this again is due to the fact how the iXML ABAP Objects wrappers interact with their C++ counterparts in the kernel. Believe me, there is no efficient way around this problem, except if the ABAP Objects language would be extended to allow operator overloading; I could then overload the cast (?=) operator to call query_interface() internally. But this is unlikely to happen.
Cheers
‎2011 Apr 18 8:06 AM
While browsing through the Where-Used list for this interface I came across report T_DOM_MANIPULATE in package SIXML_TEST.
There is an interesting part:
idx = sy-index - 1.
IF sy-saprl >= '610'.
* REL >= 6.10: we use simple cast
item ?= items->get_item( index = idx ).
ELSE.
* REL < 6.10: explicit query_interface is required
node = items->get_item( index = idx ).
item ?= node->query_interface( iid = ixml_iid_element ).
ENDIF.It looks like it is possible to use ?= operator directly since 6.10 but documentation was not updated to reflect this.