Application Development and Automation 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:Ā 
Read only

Upload and edit XML

0 Likes
3,064

Hello,

I need to upload a XML file and edit the XML to add a new node.

I try to use FUNCTION 'GUI_UPLOAD' and FUNCTION 'SMUM_XML_PARSE' but with this output i can“t add a new node.

Best Regards,

Eduardo Paiva

4 REPLIES 4
Read only

Private_Member_467521
Active Contributor
0 Likes
2,589

Hi pedro.guerreiro.gaspar,

Please kindly look into this wiki and advise if this address your topic

https://wiki.scn.sap.com/wiki/display/ABAP/iXML+-+Create+XML+file?original_fqdn=wiki.sdn.sap.com

Cheers,

Luis

Read only

0 Likes
2,589

Hi LuĆ­s,

In my search i reach to this link and I have a draft of what I want, code below:

DATA: lo_xml TYPE REF TO cl_xml_document,
lo_root TYPE REF TO if_ixml_node,
lo_xslt TYPE REF TO cl_xslt_processor,
lv_xml TYPE string.

lv_xml = '<NFe><serie>01</serie><nNF>573512</nNF><dEmi>2014-05-06</dEmi><hEmi>16:40</hEmi><item nro="1"><cod>50</cod><desc>Agua</desc></item><item nro="2"><cod>10</cod><desc>Refrigerante</desc></item><totais><valor>R$ 50,00</valor></totais></NFe>'.

CREATE OBJECT lo_xml.
lo_xml->parse_string( stream = lv_xml ).

CREATE OBJECT lo_xslt TYPE cl_xslt_processor.
lo_root = lo_xml->get_first_node( ).
lo_xslt->set_source_node( lo_root ).


lo_node = lo_xml->create_simple_element(
name = 'Company'
* parent = lo_node
VALUE = 'test').
lo_root->append_child( lo_node ).

with this code i can add a node Company with value test, but now i need to upload my XML to put in lv_xml variable.

Best Regards,

Eduardo Paiva

Read only

Sandra_Rossi
Active Contributor
0 Likes
2,589

You say "I need to upload a XML", it's not really your question, but it's part of context, please separate the question clearly. SMUM_XML_PARSE is to read "simple XML", it's not to change it.

Please search the Web, there are many questions and answers about "how to edit XML"

Please provide details if you want more relevant answers.

Read only

0 Likes
2,589

Dear Sandra,

With the code below(draft/example) i can add a node Company with value test, but now i need to upload my XML to put in lv_xml variable.

DATA: lo_xml TYPE REF TO cl_xml_document,
lo_root TYPE REF TO if_ixml_node,
lo_xslt TYPE REF TO cl_xslt_processor,
lv_xml TYPE string.

lv_xml = '<NFe><serie>01</serie><nNF>573512</nNF><dEmi>2014-05-06</dEmi><hEmi>16:40</hEmi><item nro="1"><cod>50</cod><desc>Agua</desc></item><item nro="2"><cod>10</cod><desc>Refrigerante</desc></item><totais><valor>R$ 50,00</valor></totais></NFe>'.

CREATE OBJECT lo_xml.
lo_xml->parse_string( stream = lv_xml ).

CREATE OBJECT lo_xslt TYPE cl_xslt_processor.
lo_root = lo_xml->get_first_node( ).
lo_xslt->set_source_node( lo_root ).


lo_node = lo_xml->create_simple_element(
name = 'Company'
* parent = lo_node
VALUE = 'test').
lo_root->append_child( lo_node ).

Best Regards,

Eduardo Paiva