Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

XML Parsing Question

former_member189162
Participant
0 Kudos

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

1 ACCEPTED SOLUTION

former_member189162
Participant
0 Kudos

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!!

1 REPLY 1

former_member189162
Participant
0 Kudos

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!!