06-04-2015 10:52 PM
Hi Experts,
This may be a silly question, but I can't seem to find a solution.
I have a scenario where I am parsing XML in a custom Function Module. I am attemtping to return a specific Element from the XML, let's say "<car>".
I can use:
RETURN_ELEMENT TYPE REF TO IF_IXML_ELEMENT
RETURN_ELEMENT = LO_DOCUMENT->FIND_FROM_NAME_NS( 'car' ).
But, unfortunately that only returns the first 'car' Element in the XML. If I have say, 3 or 4, 'car' Elements, like one red, blue, yellow and black, then I need to loop through them to find the one I need to return. So, I use:
LO_NODE_COLLECTION TYPE REF TO IF_IXML_NODE_COLLECTION
LO_NODE_COLLECTION = LO_DOCUMENT->GET_ELEMENTS_BY_TAG_NAME_NS( 'car' ).
And now I have a Node's collection I can loop through and find the exact 'car' Element I want. Great.
Now here is my problem, I still want my Function Module to return an IF_IXML_ELEMENT. But, even though my collection is a collection of Elements, it is a Node collection, so i have a IF_IXML_NODE.
After finding the 'car' Element I am looking for, by looping through the collection, how do I return this Node as an Element??
I am not able to Cast, or I am not using the correct syntax to Cast. Has anyone done anything similar and can point me in the right direction?
Thanks!
-Kevin
06-05-2015 7:18 AM
My friend Paul J. Modderman helped me with this. I wish i could give you a 1000 points Paul, thank you!!
Just needed to cast the correct Node found in the collection as an Element in the way he expalined below:
DATA: LO_CAR_CURR_ELEMENT TYPE REF TO IF_IXML_ELEMENT.
LO_CAR_CURR_ELEMENT ?= LO_NODE_COLLECTION->GET_ITEM( LO_NODE_COLLECTION_INDEX ).
Thanks again Paul!!
06-05-2015 7:18 AM
My friend Paul J. Modderman helped me with this. I wish i could give you a 1000 points Paul, thank you!!
Just needed to cast the correct Node found in the collection as an Element in the way he expalined below:
DATA: LO_CAR_CURR_ELEMENT TYPE REF TO IF_IXML_ELEMENT.
LO_CAR_CURR_ELEMENT ?= LO_NODE_COLLECTION->GET_ITEM( LO_NODE_COLLECTION_INDEX ).
Thanks again Paul!!