Root element add in the Primary Document
There are 3 ways to add a root element in XML structure.
1. Add a root element in the Primary Document by XSLT
· Input document:
<?xml version="1.0" encoding="UTF-8"?>
<AAA>
<BBB></BBB>
</AAA>
· XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:element name="ZZZ">
<xsl:copy-of select="*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
· BPML:
<process name="addRoot">
<sequence>
<operation name="XSLT Service">
<participant name="XSLTService"/>
<output message="XSLTServiceTypeInputMessage">
<assign to="." from="*"/>
<assign to="xslt_name">addRoot</assign>
<assign to="xml_input_from">PrimaryDoc</assign>
</output>
<input message="inmsg">
<assign to="." from="*"/>
</input>
</operation>
</sequence>
</process>
· Output document:
<?xml version="1.0" encoding="UTF-8"?>
<ZZZ>
<AAA>
<BBB>
</BBB>
</AAA>
</ZZZ>
2. Add a root element in the Primary Document by Batch Service
· Input Document:
<AAA>
<BBB>
</BBB>
</AAA>
· BPML:
<process name="default">
<sequence>
<assign to="prefix_root"><ZZZ></assign>
<assign to="suffix_root"></ZZZ></assign>
<operation name="BatchProcessor">
<participant name="BatchProcessorService"/>
<output message="BatchProcessorInputMessage">
<assign to="." from="*"/>
<assign to="suffix_document">PrimaryDocument</assign>
<assign to="use_xml">false</assign>
<assign to="prefix_document">prefix_root</assign>
</output>
<input message="inmsg">
<assign to="." from="*"/>
</input>
</operation>
<operation name="BatchProcessor">
<participant name="BatchProcessorService"/>
<output message="BatchProcessorInputMessage">
<assign to="." from="*"/>
<assign to="suffix_document">suffix_root</assign>
<assign to="use_xml">false</assign>
<assign to="prefix_document">PrimaryDocument</assign>
</output>
<input message="inmsg">
<assign to="." from="*"/>
</input>
</operation>
</sequence>
</process>
· Output document:
<ZZZ>
<AAA>
<BBB>
</BBB>
</AAA>
</ZZZ>
3. Add a root element by Translation Map
We can create a simple map, positional to positional, with only one record and one field inside the record, in the input side.
Output side can have only one record.
No direct links!
· INPUT (root ) element, extended rule, OnBegin:
writeblock("<ZZZ>");
· Extended rule on field level in the input side:
string[255] buffer;
while readblock(buffer) do writeblock(buffer);
· INPUT (root ) element, extended rule, OnEnd:
writeblock("</ZZZ>");