rajaa_sekaran
New Member
My GoalI need to create an XElement that appears in my document a dynamic number of times based on the combination of Placement_ID and Fill_ID. If the record in my object list has the same Placement_ID as another record, I want to append another fill XElement with a different Fll_ID underneath the prior one. Example below:\[code\]<envelope ack="entity" transaction="multi"> <auth> <user>TM_DEV</user> <session>session1</session> </auth> <Trading op="createOrder, pretradeCpl, sendToTrading,createPlacement, createFill" id="os1"> <order op="create" id="test1234"> <scenario id="sample" /> <execBroker>BEAR</execBroker> <ticker>MSFT</ticker> <trader>TM_DEV</trader> <instruction>LIM</instruction> <limitPrice>85</limitPrice> <transType>BUYL</transType> <orderDuration>GTC</orderDuration> <tradeDate> </tradeDate> <settleDate> </settleDate> <allocation id="" op="create"> <acctCd>tstacc00006</acctCd> <targetQty>300</targetQty> <specialInst /> </allocation> <placement id="Place1" op="create"> <execBroker>BEAR</execBroker> <placeQty>300</placeQty> <fill id="fill1" op="create"> <fillQty>150</fillQty> <fillPrice>43</fillPrice> </fill> <fill id="fill2" op="create"> <fillQty>150</fillQty> <fillPrice>44</fillPrice> </fill> </placement> </order> </Trading>\[/code\]My ProgressThe code below that I have written so far queries a list object and produces a new order for each row. I need to be able to group my list by Placement_ID and if their are two rows with the same Placement_ID then I want it to write multiple Fill elements. Otherwise, if there are no duplicate Placement_IDs, then there would be 1 order, 1 placement and 1 fill for each row of data in the list.\[code\]XDocument doc = new XDocument( new XDeclaration("1.0", "UTF-8", "yes"), new XElement("envelope", new XAttribute("ack", "entity"), new XAttribute("transaction", "multi"), new XElement("auth", new XElement("user", "TM_DEV"), new XElement("session", "session1")), new XElement("trading", new XAttribute("op", "createOrder, pretradeCpl, sendToTrading, createPlacement, createFill"), new XAttribute("id", "os1"), from t in trades.ToList() select new XElement("order", new XAttribute("op", "create"), new XAttribute("id", DateTime.Now.ToString("yyMMddHHmmssfff") + t.OrderId), new XElement("Scenario", new XAttribute("id", "sample")), new XElement("execBroker", t.ExecBrkID), new XElement("ticker", t.Ticker), new XElement("sedol", t.Sedol), new XElement("Trader", "TM_DEV"), new XElement("transType", t.TransType), new XElement("orderDuration", "GTC"), new XElement("tradeDate", ""), new XElement("settleDate", ""), new XElement("allocation", new XAttribute("id", ""), new XAttribute("op", "create"), new XElement("acctCd", t.Account), new XElement("targetQty", t.TargetQty), new XElement("specialInst", "who to settle with")), new XElement("placement", new XAttribute("op", "create"), new XAttribute("id", t.PlacementId), new XElement("execBroker", t.ExecBrkID), new XElement("placeQty", t.ExecQty), new XElement("fill", new XAttribute("id", t.FillId), new XAttribute("op", "create"), new XElement("fillQty", t.ExecQty), new XElement("fillPrice", t.ExecPrice)))))));\[/code\]