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

XML

Former Member
0 Likes
352

Hello, is there an easy way to create an XML File with this schema?

<?xml version="1.0" encoding="utf-16"?>
<Persons>
    <Identity Name="Charles" Name2="Mayer" Job="Development" />
    <Identity Name="Max" Name2="Mayer" Job="Sales" />
</Persons>

1 ACCEPTED SOLUTION
Read only

athavanraja
Active Contributor
0 Likes
274

check this sample code.


REPORT  yxmlattribute.

TYPES: BEGIN OF p_type ,
       identity(10),
       END OF p_type .
DATA: l_xml  TYPE REF TO cl_xml_document  ,
     if_xml TYPE REF TO if_ixml_document ,
     node TYPE REF TO if_ixml_node  .
data: wa_persons type p_type .
DATA: xml_out TYPE string .


CALL TRANSFORMATION id
      SOURCE persons = wa_persons
      RESULT XML xml_out.


CREATE OBJECT l_xml.

CALL METHOD l_xml->parse_string
  EXPORTING
    stream = xml_out.


node = l_xml->find_node(
    name   = 'IDENTITY'
*    ROOT   = ROOT
       ).

l_xml->set_attribute(
    name    = 'Name'
    value   = 'Charles'
    node    = node
       ).

l_xml->set_attribute(
    name    = 'Name2'
    value   = 'Mayer'
    node    = node
       ).
l_xml->set_attribute(
      name    = 'Job'
      value   = 'Development'
      node    = node
         ).

CALL METHOD l_xml->display.

Regards

Raja

1 REPLY 1
Read only

athavanraja
Active Contributor
0 Likes
275

check this sample code.


REPORT  yxmlattribute.

TYPES: BEGIN OF p_type ,
       identity(10),
       END OF p_type .
DATA: l_xml  TYPE REF TO cl_xml_document  ,
     if_xml TYPE REF TO if_ixml_document ,
     node TYPE REF TO if_ixml_node  .
data: wa_persons type p_type .
DATA: xml_out TYPE string .


CALL TRANSFORMATION id
      SOURCE persons = wa_persons
      RESULT XML xml_out.


CREATE OBJECT l_xml.

CALL METHOD l_xml->parse_string
  EXPORTING
    stream = xml_out.


node = l_xml->find_node(
    name   = 'IDENTITY'
*    ROOT   = ROOT
       ).

l_xml->set_attribute(
    name    = 'Name'
    value   = 'Charles'
    node    = node
       ).

l_xml->set_attribute(
    name    = 'Name2'
    value   = 'Mayer'
    node    = node
       ).
l_xml->set_attribute(
      name    = 'Job'
      value   = 'Development'
      node    = node
         ).

CALL METHOD l_xml->display.

Regards

Raja