cancel
Showing results for 
Search instead for 
Did you mean: 

Namespace in a tag

Former Member
0 Kudos

Hi,

In an ABAP mapping (thus a class interface), how can I add and manage the namespace in a tag thanks to a prefix?

Currently, I have an outbound XML message like this:

  <MT00314_WTFR>
       <row>
          <etc......>

and I would like to have this one:

  <ns:MT00314_WTFR xmlns:ns="http://my_namespace">
       <row>
          <etc......>

I have already try to use some methods but without success

Anybody can help me !

Regards

Mickael

Accepted Solutions (1)

Accepted Solutions (1)

udo_martens
Active Contributor
0 Kudos

Hi Mickael,

u can use replace:



  REPLACE
    'MT00314' WITH 'ns:MT00314_WTFR xmlns:ns="http://my_namespace"' INTO g_myString.

To convert input to string use:

ECATT_CONV_XSTRING_TO_STRING,

to convert back use:

ECATT_CONV_STRING_TO_XSTRING

Regards,

Udo

Former Member
0 Kudos

Hi Udo,

In that case, you creates a <tag></tag> like this:

  <ns:MT00314_WTFR xmlns:ns="http://my_namespace">
  ...
  </ns:MT00314_WTFR <b>xmlns:ns="http://my_namespace"</b>>
  ------------------^

Unfortunately, </tag> cannot have the namespace and there is a dump. XI needs to have:

  <ns:MT00314_WTFR xmlns:ns="http://my_namespace">
  ...
  <b></ns:MT00314_WTFR></b>

I will search how to use other methods like "set_namespace_prefix".

Mickael

stefan_grube
Active Contributor
0 Kudos

what about:

REPLACE
    '<MT00314' WITH '<ns:MT00314_WTFR xmlns:ns="http://my_namespace"' INTO g_myString.

REPLACE
    '</MT00314' WITH '</ns:MT00314_WTFR' INTO g_myString.

?

udo_martens
Active Contributor
0 Kudos

Hi Mickael,

is this ur first ABAP programm?

Regards,

Udo

Former Member
0 Kudos

hI Stefan,

No... because I don't build manually the <tag></tag> in the outbound message, it's automatically generated by using a method (e.g create_simple_element)

Former Member
0 Kudos

Hi Udo,

This is the 2nd, but it's the 1st times by using an ABAP mapping AND a block inside a BPM.

And I know well the abap environment and less the abap-object.

stefan_grube
Active Contributor
0 Kudos

This code didn't work.

Stefan

Message was edited by: Stefan Grube

Former Member
0 Kudos

Hi Stefan,

By using :

elementsender = odocument->create_simple_element(
name = 'SenderService'
namespace = 'YourNamespace'
value = l_sender_service
parent = msgtype ).

I think you cannot precise the prefix "ns:"... I'll check.

yes I use this doc but is not adapted in my case.

Because the final file is not a flat file (like in this doc) but a structured file.

P.S: sorry, today I'm between tests, meeting and scheduling: I didn't find time to do other tests with another method.

stefan_grube
Active Contributor
0 Kudos

Now it works:

data: odocument type ref to if_ixml_document.
odocument = ixmlfactory->create_document( ).
data: msgtype type ref to if_ixml_element.
msgtype = odocument->create_simple_element(
name = 'MsgOut'
namespace = 'ns0'
parent = odocument ).

data rc like sy-subrc.
rc = msgtype->set_attribute(
name = 'xmlns:ns0' 
value = 'http://xi.com/mapping/exercise5' ).

Stefan

Former Member
0 Kudos

Exact Stefan, namespace+prefixe are correctly inside the tag.

Unfortunately, I have realized a test of my flow and it seems that it's not enough for using the block : the output message of transformation N°2 (a very easy graph mapping) is still empty. Agrrrhhh :-((

But a GREAT thanks to you Stefan, that help me.

Answers (1)

Answers (1)

Andrzej_Filusz
Contributor
0 Kudos

Hi!!!

I suppose you are looking for something like that:

data: result_document type ref to IF_IXML_DOCUMENT.

data: result_xml_doc type ref to CL_XML_DOCUMENT.

result_xml_doc->CREATE_EMPTY_DOCUMENT( ).

result_document = g_ixml->create_document( ).

parent = result_document->create_simple_element(

name = 'ns:MyRootTagName'

parent = result_document ).

element = result_document->create_simple_element(

name = 'name'

value = firstname

parent = parent ).

(...)

/// some create_simple_element lines here

(...)

result_xml_doc->CREATE_WITH_DOM( DOCUMENT = result_document ).

result_xml_doc->SET_ENCODING( 'UTF-8' ).

result_xml_doc->ADD_NAMESPACE_DEF( ALIAS = 'ns'

URI = 'http://your_namespace' ).

Regards,

Andrzej Filusz

Former Member
0 Kudos

Hi Andrzej,

In fact, I have something like that, but I will test your solution.


**=== 4. Build up output document: XML tags ===
* Create output document
  data: odocument type ref to if_ixml_document.
  odocument = ixmlfactory->create_document( ).

* Create an element 'root' (unique) on output document
  data: v_root type ref to if_ixml_element.
* v_root = odocument->create_simple_element_ns(
  v_root = odocument->create_simple_element(
              name       = 'MT00314_WTFR'      "<<< pb
*             namespace  = my_ns               "<<< pb
              parent     = odocument ).
*...
* add element fields on this 'root'...
*...

* Add a node to the output document
  data: irc type i.
  irc = '1'.

**=== 5. Render document ===
* Create output stream
  data: ostream type ref to if_ixml_ostream.
  ostream = streamfactory->create_ostream_xstring( result ).

* Create renderer
  data: renderer type ref to if_ixml_renderer.
  renderer = ixmlfactory->create_renderer(
               ostream  = ostream
               document = odocument ).
  irc = renderer->render( ).