I will get a fIXML message like below.
<FIXML v="4.4" xsi:schemaLocation="../../schema/fixml-main-4-4.xsd" xmlns="http://www.fixprotocol.org/FIXML-4-4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Main attr1="19000" attr2="10">
<Hdr hattr1="ABC" hattr2="DEF"/>
<Insert1 I1attr1 ="2008-08" I1attr2 ="20080810"/>
<Insert2 I2attr1="A111C" I2attr2 ="123">
<sub ID="1AC"/>
</Insert2>
<Insert2 I2attr1="A222C" I2attr2 ="456">
<sub ID="1BC"/>
</Insert2>
</Main>
</FIXML>
From this I need to check the mandatory sections are present or not if not present then have to add them by self closing the tag.
After the <Hdr ..>
element check <Insert1../>
element is there or not, if present keep that section as is, if not present then have to add <Insert1/>
self close tag after the <Hdr ..>
element, then check for <Insert2.../>
if present keep that element after <Insert1 .../>
or <Insert1/>
if not present add after the <Insert1/>
.
To form an xml like this.
<FIXML v="4.4" xmlns="http://www.fixprotocol.org/FIXML-4-4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Main attr1="19000" attr2="10">
<Hdr hattr1="ABC" hattr2="DEF"/>
<Insert1/>
<Insert2>
<sub/>
</Insert2>
<Insert2>
<sub/>
</Insert2>
</Main>
</FIXML>
Please suggest.
Thanks in advance.