EDN Admin
Well-known member
<pre class="prettyprint Hi All - I am trying to understand if theres any way to conctnate two variables of XElement? Or try adding an Elements while writing xmldocument?
I am able to generate below document, however, u nable to try grouping multiples groups in withing single element.
I am using below code to build - and getting output - however, unable to add groupings.
<Root>
<deals>
<deal>
<dealid> D1 </dealid>
<Trade> T1</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Trade> T2</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Group> g1 </Group>
<Group> g2 </group>
</deal>
<deal>
<dealid> D2 </dealid>
<Trade> T1</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Trade> T2</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Group> g3 </Group>
<Group> g4 </group>
</deal>
</deals>
<Root>
Expected output - expecting to Add extra element <Groups> while creating document, but not been able to - any pointers , help?
<Root>
<deals>
<deal>
<dealid> D1 </dealid>
<Trade> T1</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Trade> T2</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Groups>
<Group> g1 </Group>
<Group> g2 </group>
</Groups>
</deal>
<deal>
<dealid> D2 </dealid>
<Trade> T1</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Trade> T2</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Groups>
<Group> g3 </Group>
<Group> g4 </group>
</Groups>
</deal>
</deals>
<Root>
My sample code
Public void CreatXML(inputList)
inputList // Is my pre-build Dictcionay , which I an trying to print ot output/
{
Xemelemnt = xtransactionInput.Add
foreach (var value in inputList)
{
xtransactionInput = (new XElement("deal", new XElement("dealId", new XElement("id", value.Key, new XAttribute("type", "fiDealId"), new XAttribute("version", "")))));
// Checlf if TTS type or Trade Sub Type is populated
subType = (subType == null) || subType == "" ? value.Value[iCount].TradeSubType : subType;
xtransactionInput.Add
(new XElement("Trade", new XElement("partyId", new XElement("id", value.Value[iCount].TradeId, new XAttribute("type", "abv")))),
new XElement("Details", new XElement("partyId", new XElement("id", value.Value[iCount].Details, new XAttribute("type", "acc")))),
new XElement("Details", new XElement("mainType", new XElement("id", value.Value[iCount].Details1, new XAttribute("type", "aaa"))),
new XElement("subType", new XElement("id", value.Value[iCount].TradeSubType, new XAttribute("type", "aaa")))));
foreach (var element in value.Value)
{
xtransactionInput.Add(new XElement("Group", value.Value[iCount].Group)
}
Utils.WriteTxn(Xemelemnt) // CLass whioch outputs filnal file.
} [/code]
<br/>
<br/>
View the full article
I am able to generate below document, however, u nable to try grouping multiples groups in withing single element.
I am using below code to build - and getting output - however, unable to add groupings.
<Root>
<deals>
<deal>
<dealid> D1 </dealid>
<Trade> T1</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Trade> T2</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Group> g1 </Group>
<Group> g2 </group>
</deal>
<deal>
<dealid> D2 </dealid>
<Trade> T1</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Trade> T2</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Group> g3 </Group>
<Group> g4 </group>
</deal>
</deals>
<Root>
Expected output - expecting to Add extra element <Groups> while creating document, but not been able to - any pointers , help?
<Root>
<deals>
<deal>
<dealid> D1 </dealid>
<Trade> T1</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Trade> T2</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Groups>
<Group> g1 </Group>
<Group> g2 </group>
</Groups>
</deal>
<deal>
<dealid> D2 </dealid>
<Trade> T1</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Trade> T2</Trade>
<Details> dt1 </Details>
<Details> dt2 </Details>
<Groups>
<Group> g3 </Group>
<Group> g4 </group>
</Groups>
</deal>
</deals>
<Root>
My sample code
Public void CreatXML(inputList)
inputList // Is my pre-build Dictcionay , which I an trying to print ot output/
{
Xemelemnt = xtransactionInput.Add
foreach (var value in inputList)
{
xtransactionInput = (new XElement("deal", new XElement("dealId", new XElement("id", value.Key, new XAttribute("type", "fiDealId"), new XAttribute("version", "")))));
// Checlf if TTS type or Trade Sub Type is populated
subType = (subType == null) || subType == "" ? value.Value[iCount].TradeSubType : subType;
xtransactionInput.Add
(new XElement("Trade", new XElement("partyId", new XElement("id", value.Value[iCount].TradeId, new XAttribute("type", "abv")))),
new XElement("Details", new XElement("partyId", new XElement("id", value.Value[iCount].Details, new XAttribute("type", "acc")))),
new XElement("Details", new XElement("mainType", new XElement("id", value.Value[iCount].Details1, new XAttribute("type", "aaa"))),
new XElement("subType", new XElement("id", value.Value[iCount].TradeSubType, new XAttribute("type", "aaa")))));
foreach (var element in value.Value)
{
xtransactionInput.Add(new XElement("Group", value.Value[iCount].Group)
}
Utils.WriteTxn(Xemelemnt) // CLass whioch outputs filnal file.
} [/code]
<br/>
<br/>
View the full article