2012 Nov 14 4:23 PM
Hello All,
I want to generate XML file in below format
<Root>
<Node count = '1'>
.....
.....
</Node>
<Node count = '2'>
.....
.....
</Node>
<Node count = '3'>
.....
.....
</Node>
</Root>
The closing node of <Node count> is <Node>.
and the value present in single code should increment by one for every next node.
I am able to get the closing node of <Node count> as </Node>, but unable to get the counter value.
I am trying to do it be variables etc but could not get the exact logic.
Requesting to help in this regard.
With regards,
Sandeep Akella
2012 Nov 14 8:09 PM
Hi Sandeep,
You can use a simple transformation to generate the xml file.
Example:
SIMPLE TRANSFORMATION
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<root>
<tt:loop ref=".ROOT" name="line">
<node>
<tt:attribute name="count" value-ref="$line.node.count" />
</node>
</tt:loop>
</root>
</tt:template>
</tt:transform>
REPORT
REPORT ztest_node_count.
TYPES: BEGIN OF type_node_attr,
count TYPE i,
END OF type_node_attr,
BEGIN OF type_xml,
node TYPE type_node_attr,
END OF type_xml.
DATA: t_xml TYPE STANDARD TABLE OF type_xml,
s_xml TYPE type_xml,
strxml TYPE string.
START-OF-SELECTION.
s_xml-node-count = 1.
APPEND s_xml TO t_xml.
s_xml-node-count = 2.
APPEND s_xml TO t_xml.
s_xml-node-count = 3.
APPEND s_xml TO t_xml.
CALL TRANSFORMATION znodes
SOURCE root = t_xml
RESULT XML strxml.
Reference: http://help.sap.com/saphelp_erp60_sp/helpdata/en/48/c21940a65ec442e10000000a1550b0/content.htm
Regards,
Christian
2012 Nov 15 1:38 AM
Hello Christian,
Thank you for your reply.
By folowing your code I will get XML file as
<Root>
<Node> 1
</Node>
<Node> 2
</Node>
<Node> 3
</Node>
</Root>
But my requirement is
<Root>
<Node count = "1">
.....
Some inner tags
......
</Node>
<Node count = "2">
.....
Some inner tags
......
</Node>
<Node count = "3">
.....
Some inner tags
......
</Node>
</Root>
count and its value is inside the xml tag.
with regards,
Sandeep Akella
2012 Nov 15 6:27 AM
Hi Sandeep,
The code below generates an empty tag node with an attribute count.
<node>
<tt:attribute name="count" value-ref="$line.node.count" />
</node>
So if you run the report the result xml (strxml) will be:
<Root>
<Node count = "1" />
<Node count = "2" />
<Node count = "3" />
</Root>
2012 Nov 15 7:15 AM
Hello Christian,
Thank you for your reply.
Can we get the value of the attribute dynamically like from a field of internal table.
With regrds,
Sandeep Akella
2012 Nov 15 7:26 AM
Hello Christian,
Thank you for your reply.
Can we get the value of the attribute dynamically like from a field of internal table.
With regrds,
Sandeep Akella
2012 Nov 15 8:27 AM
Hello Christian,
Thank you for your reply.
Can we get the value of the attribute dynamically like from a field of internal table.
With regrds,
Sandeep Akella
2012 Nov 15 9:23 AM
Hi Sandeep,
That's exactly what the example report is doing
Populating the internal table t_xml
s_xml-node-count = 1.
APPEND s_xml TO t_xml.
s_xml-node-count = 2.
APPEND s_xml TO t_xml.
s_xml-node-count = 3.
APPEND s_xml TO t_xml.
and then passing the internal table as the source for the transformation
CALL TRANSFORMATION znodes
SOURCE root = t_xml
RESULT XML strxml.
Hope it helps.
Regards,
Christian
2012 Nov 15 11:01 AM
Hello Christian,
Thank you for your reply.
Can we get the value of the attribute dynamically like from a field of internal table.
With regrds,
Sandeep Akella