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 with namespace

Former Member
0 Kudos
154

Hi All,

I have a requirement to convert XML to itab to be processed further.

I couldn't parse the XML which contains ns0 (namespace?) as following:

<ns0:OrderNo>887140</ns0:OrderNo>

<ns0:CPROD>BD</ns0:CPROD>

<ns0:CURR>USD</ns0:CURR>

I'm able to parse If I remove the namespace ns0 from the file as following:

<OrderNo>887140</OrderNo>

<CPROD>BD</CPROD>

<CURR>USD</CURR>

The thing is the XML file will always come with the namespace ns0.

I'm using IF_IXML, IF_IXML_STREAM_FACTORY, IF_IXML_ISTREAM, IF_IXML_PARSER, IF_IXML_DOCUMENT to parse the XML.

Any idea on how to overcome this?

Thanks,

Victor.

1 ACCEPTED SOLUTION

hendrik_brandes
Contributor
0 Kudos
60

Hello Victor,

try to use XSLT Transformations.

Thereby you will gain a lot of features, including the XSLT-Editor and a very smooth integration in ABAP.

Kind regards,

Hendrik

4 REPLIES 4

hendrik_brandes
Contributor
0 Kudos
61

Hello Victor,

try to use XSLT Transformations.

Thereby you will gain a lot of features, including the XSLT-Editor and a very smooth integration in ABAP.

Kind regards,

Hendrik

0 Kudos
60

Hi Hendrik,

Thanks for your reply.

I haven't try to use XSLT for this. But Sure I will try this in the future.

As for my case now,

The XML is quite complex and I have build a FM by using standard SAP class mentioned earlier to parse and assign the value dynamically to the internal table. Everything works fine when all the tag doesn't come out with the namespace ns0.

I'm thinking I might missed out something to tell SAP during parsing the XML that this XML document is comes with namespace ns0.

Thanks,

Victor.

0 Kudos
60

Dear All,

I've solved my problem.

I just need to pass the namespace ('ns0' in my case) during search of the tag.

Interface: IF_IXML_DOCUMENT

Method get_elements_by_tag_name( name = xml_row namespace = namespace ).

Thanks,

Victor.

0 Kudos
60

Hello Victor,

fine. I am glad, I could help you.

Just one note to XSLT Transformations: When using them, you got even the ability to map directly to internal abap tables:

CALL TRANSFORMATION ZXSLT_YOUR_TRANSFORMATION

SOURCE XML l_xmlstring

RESULT DATA = lt_data.

You just need to transform you xml to the asx:abap name space and that's it

Look at , where I show a simple example, how this works.

Kind regards,

Hendrik