How to generate xml file using XDocument in loop

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
here is my code which is not throwing error but output xml structure is not right

here is code

XDocument xDoc = new XDocument(new XElement("TickerBrokerStandardDateLineitem",
/*new XDeclaration("1.0", "utf-8", "yes"),*/
new XElement("Ticker"),
new XElement("TickerID"),
new XElement("TickerBrokerStandardDateLineitemValues")));

for (int x = 0; x <= TenQKbogeyData.Rows.Count - 1;x++ )
{
xDoc.Root.Add(new XElement("TickerBrokerStandardDateLineitemValue",
new XElement("TabName", TenQKbogeyData.Rows[x]["TabName"]),
new XElement("StandardDate", TenQKbogeyData.Rows[x]["StandardDate"]),
new XElement("XFundCode", TenQKbogeyData.Rows[x]["XFundCode"]),
new XElement("BRTab", TenQKbogeyData.Rows[x]["BRTab"]),
new XElement("BRLineItem", TenQKbogeyData.Rows[x]["BRLineItem"]),
new XElement("StandardLineItem", TenQKbogeyData.Rows[x]["StandardLineItem"]),
new XElement("ActualProvidedByCompany", TenQKbogeyData.Rows[x]["ActualProvidedByCompany"])));
}

xDoc.Save(strpath);

TenQKbogeyData is data table and i am iterate in loop for data table and adding data

all TickerBrokerStandardDateLineitemValue will be inside of TickerBrokerStandardDateLineitemValues root node

but in my case TickerBrokerStandardDateLineitemValues is empty at top which is wrong. so guide me how to write the code.

thanks

Continue reading...
 
Back
Top