on 09-07-2005 6:29 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
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
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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( ).
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.