csv to xml not adding xElement if XAttribute = "" - c#

I've create an xml file from a csv file like this
private void button2_Click(object sender, EventArgs e)
{
String[] FileContent = File.ReadAllLines(csvPathFile);
String XMLNS = "";
int idCountProduct = 1;
XElement Inv = new XElement("data",
from items in FileContent
let fields = items.Split(';')
select new XElement("category",
new XAttribute("idCategory", fields[0]),
new XAttribute("CategoryName", fields[1]),
new XElement("products",
new XElement("product",
new XAttribute("IdProduct", idCountProduct++),
new XAttribute("Rif", fields[0]),
new XAttribute("ProductName", fields[2]),
new XElement("products",
new XElement("product",
new XAttribute("IdProduct", idCountProduct++),
new XAttribute("Rif", fields[0]),
new XAttribute("ProductName", fields[3]),
new XElement("products",
new XElement("product",
new XAttribute("IdProduct", idCountProduct++),
new XAttribute("Rif", fields[0]),
new XAttribute("ProductName", fields[4]));
File.WriteAllText(xmlPathFile, XMLNS + Inv.ToString());
}
this is my csv file
1;Beverages;Lemon Juice;;Orange Juice
this is the xml file i want to create
<data>
<category idCategory="1" CategoryName= "Beverages">
<products>
<product IdProduct="1" Rif="1" ProductName= "Lemon Juice" />
<product IdProduct="2" Rif="1" ProductName= "Orange Juice" />
<products/>
<category/>
</data>
and this is the xml file i obtain
<data>
<categories>
<category idCategory="1" CategoryName= "Beverages">
<products>
<product IdProduct="1" Rif="1" ProductName= "Lemon Juice" />
<product IdProduct="2" Rif="1" ProductName= "" />
<product IdProduct="3" Rif="1" ProductName= "Orange Juice" />
<products/>
<category/>
<categories/>
</data>
How can I avoid adding a product if ProductName is not assigned?

Add a filter to your LINQ query to filter out empty products:
where !String.IsNullOrEmpty(fields[4])
just after this:
let fields = items.Split(';')
Anyway if your condition is so simple you do not even need it and you may filter out entries from the Split instruction itself:
let fields = items.Split(';', StringSplitOptions.RemoveEmptyEntries)
EDIT
Your code is pretty fixed so...are you sure you need to use LINQ and LINQ-to-XML? I guess it'll be even more readable anyway...write this:
XElement data = new XElement("data");
XDocument document = new XDocument(data);
int counter = 0;
foreach (string entry in File.ReadAllLines(csvPath))
{
string[] fields = entry.Split(new char[] { ';' },
StringSplitOptions.RemoveEmptyEntries);
XElement category = new XElement("category",
new XAttribute("idCategory", fields[0]),
new XAttribute("CategoryName", fields[1]));
data.Add(category);
XElement products = new XElement("products");
category.Add(products);
for (int i = 2; i < fields.Length; ++i)
{
products.Add(new XElement("product",
new XAttribute("IdProduct", counter++),
new XAttribute("Rif", fields[0]),
new XAttribute("ProductName", fields[i])));
}
}
document.Save(xmlPath);
}

Related

Assistance with how to properly create an xml file in c#

I'm working in c#, and I was needing to convert a .csv to xml. I pretty much got it down, and understand how to do it. However I'm struggling to have it right with how i need it setup.
XNamespace xNamespace = "urlhere";
XElement newXML = new XElement(xNamespace + "WarehouseReceipts",
new XAttribute("xmlns", "urlhere"),
from str in csv
let fields = str.Split(',')
select new XElement("WarehouseReceipt",
new XAttribute("Type", "WH"),
new XElement("Number", fields[9]),
new XElement("ShipperName", fields[10]),
new XElement("ConsigneeName", fields[11]),
new XElement("Items",
new XElement("Item",
new XAttribute("Type", "WI"),
new XElement("Satus", fields[0]),
new XElement("Pieces", fields[3]),
new XElement("Description", fields[2]),
new XElement("PackageName", fields[1]),
new XElement("Length",
new XAttribute("Unit", "in"), fields[4]),
new XElement("Volume",
new XAttribute("Unit", "ft3"), fields[8]),
new XElement("Height",
new XAttribute("Unit", "in"), fields[8]),
new XElement("Width",
new XAttribute("Unit", "in"), fields[6]),
new XElement("Weight",
new XAttribute("Unit", "lb"), fields[7]),
new XElement("WarehouseReceiptNumber", fields[9])
)
),
new XElement("MeasurementUnits",
new XElement("LengthUnit", "in"),
new XElement("VolumeUnit", "ft3"),
new XElement("WeightUnit", "lb")
)
)
);
return newXML;
Now, I will show you what the prints out in the console, so you can have an idea of how it comes out in the xml format.
<WarehouseReceipts xmlns="urlhere">
<WarehouseReceipt Type="WH" xmlns="">
<Number>"3519"</Number>
<ShipperName>"4 NET NETWORKING CORP"</ShipperName>
<ConsigneeName>"ACUAMAR"</ConsigneeName>
<Items>
<Item Type="WI">
<Satus>"On Hand"</Satus>
<Pieces>"10"</Pieces>
<Description>"APPLE NEW IPAD"</Description>
<PackageName>"Case"</PackageName>
<Length Unit="in">"5.00"</Length>
<Volume Unit="ft3">"0.60"</Volume>
<Height Unit="in">"0.60"</Height>
<Width Unit="in">"4.00"</Width>
<Weight Unit="lb">"10.00"</Weight>
<WarehouseReceiptNumber>"3519"</WarehouseReceiptNumber>
</Item>
</Items>
<MeasurementUnits>
<LengthUnit>in</LengthUnit>
<VolumeUnit>ft3</VolumeUnit>
<WeightUnit>lb</WeightUnit>
</MeasurementUnits>
</WarehouseReceipt>
<WarehouseReceipt Type="WH" xmlns="">
<Number>"3519"</Number>
<ShipperName>"4 NET NETWORKING CORP"</ShipperName>
<ConsigneeName>"ACUAMAR"</ConsigneeName>
<Items>
<Item Type="WI">
<Satus>"On Hand"</Satus>
<Pieces>"20"</Pieces>
<Description>"APPLE IMAC "</Description>
<PackageName>"Box"</PackageName>
<Length Unit="in">"35.00"</Length>
<Volume Unit="ft3">"273.40"</Volume>
<Height Unit="in">"273.40"</Height>
<Width Unit="in">"15.00"</Width>
<Weight Unit="lb">"400.00"</Weight>
<WarehouseReceiptNumber>"3519"</WarehouseReceiptNumber>
</Item>
</Items>
<MeasurementUnits>
<LengthUnit>in</LengthUnit>
<VolumeUnit>ft3</VolumeUnit>
<WeightUnit>lb</WeightUnit>
</MeasurementUnits>
</WarehouseReceipt>
</WarehouseReceipts>
That whats above, is incorrect, and i need it to come out how it is shown below.
<WarehouseReceipts xmlns="urlhere">
<WarehouseReceipt Type="WH">
<Number>WR-1-22</Number>
<ShipperName>shipper</ShipperName>
<ConsigneeName>consignee</ConsigneeName>
<Items>
<Item Type="WI">
<Status>OnHand</Status>
<Pieces>3</Pieces>
<Description>description2</Description>
<PackageName>Package type2</PackageName>
<WHRItemID>2</WHRItemID>
<Length Unit="in">4.00</Length>
<Height Unit="in">4.00</Height>
<Width Unit="in">4.00</Width>
<Weight Unit="lb">6.00000000000000088818</Weight>
<Volume Unit="ft3">0.11000000000000000056</Volume>
<Model>model2</Model>
<WarehouseReceiptNumber>WR-1-22</WarehouseReceiptNumber>
</Item>
<Item Type="WI">
<Status>OnHand</Status>
<Pieces>4</Pieces>
<Description>description</Description>
<PackageName>Package type</PackageName>
<LocationCode>RCV01</LocationCode>
<Length Unit="in">1.00</Length>
<Height Unit="in">3.00</Height>
<Width Unit="in">2.00</Width>
<Weight Unit="lb">16.00</Weight>
<Volume Unit="ft3">0.01000000000000000021</Volume>
<Model>model</Model>
<WarehouseReceiptNumber>WR-1-22</WarehouseReceiptNumber>
</Item>
</Items>
<MeasurementUnits>
<LengthUnit>in</LengthUnit>
<VolumeUnit>ft3</VolumeUnit>
<WeightUnit>lb</WeightUnit>
</MeasurementUnits>
</WarehouseReceipt>
</WarehouseReceipts>
Any assistance on where i went wrong, would be greatly appreciated.
I used beyond compare to find difference. Not sure what you need help with. See picture
You are doing too much in one statement. See following :
XNamespace xNamespace = "urlhere";
string[] csv = null;
XElement WarehouseReceipt = null;
XElement items = null;
for(int i = 0; i < csv.Length; i++)
{
string[] fields = csv[i].Split(new char[] {','});
if(i == 0)
{
XElement newXML = new XElement(xNamespace + "WarehouseReceipts",
new XAttribute("xmlns", "urlhere"),
new XElement("WarehouseReceipt",
new XAttribute("Type", "WH"),
new XElement("Number", fields[9]),
new XElement("ShipperName", fields[10]),
new XElement("ConsigneeName", fields[11])
));
WarehouseReceipt = newXML.Descendants("WarehouseReceipt").FirstOrDefault();
items = new XElement("Items");
WarehouseReceipt.Add(items);
}
items.Add(new XElement("Item",
new XAttribute("Type", "WI"),
new XElement("Satus", fields[0]),
new XElement("Pieces", fields[3]),
new XElement("Description", fields[2]),
new XElement("PackageName", fields[1]),
new XElement("Length",
new XAttribute("Unit", "in"), fields[4]),
new XElement("Volume",
new XAttribute("Unit", "ft3"), fields[8]),
new XElement("Height",
new XAttribute("Unit", "in"), fields[8]),
new XElement("Width",
new XAttribute("Unit", "in"), fields[6]),
new XElement("Weight",
new XAttribute("Unit", "lb"), fields[7]),
new XElement("WarehouseReceiptNumber", fields[9])
));
WarehouseReceipt.Add(new XElement("MeasurementUnits",
new XElement("LengthUnit", "in"),
new XElement("VolumeUnit", "ft3"),
new XElement("WeightUnit", "lb")
));
}

XElement with LINQ add node after specific node

I've got this XML:
<?xml version="1.0" encoding="utf-8"?>
<JMF SenderID="InkZone-Controller" Version="1.2">
<Command ID="cmd.00695" Type="Resource">
<ResourceCmdParams ResourceName="InkZoneProfile" JobID="K_41">
<InkZoneProfile ID="r0013" Class="Parameter" Locked="false" Status="Available" PartIDKeys="SignatureName SheetName Side Separation" DescriptiveName="Schieberwerte von DI" ZoneWidth="32">
<InkZoneProfile SignatureName="SIG1">
<InkZoneProfile Locked="False" SheetName="S1">
<InkZoneProfile Side="Front">
<ColorPool Class="Parameter" DescriptiveName="Colors for the job" Status="Available">
<InkZoneProfile Separation="PANTONE 647 C" ZoneSettingsX="0 0,003 " />
</ColorPool>
</InkZoneProfile>
</InkZoneProfile>
</InkZoneProfile>
</InkZoneProfile>
</ResourceCmdParams>
</Command>
</JMF>
I'm trying to add a node after a specific node() , using XElement and Linq. But my LINQ query always returns me null.
Tried this:
XElement InkZonePath = XmlDoc.Element("JMF").Elements("InkZoneProfile").Where(z => z.Element("InkZoneProfile").Attribute("Side").Value == "Front").SingleOrDefault();
And this:
XmlDoc.Element("JMF")
.Elements("InkZoneProfile").Where(InkZoneProfile => InkZoneProfile.Attribute("Side")
.Value == "Front").FirstOrDefault().AddAfterSelf(new XElement("InkZoneProfile",
new XAttribute("Separation", x.colorname),
new XAttribute("ZoneSettingsX", x.colorvalues)));
I've built this queries following those examples:
Select XElement where child element has a value
Insert XElements after a specific node
LINQ-to-XML XElement query NULL
But it didn't worked as expected. What is wrong with the LINQ Query ? From what i've read it should work (logically reading the expression i can understand it).
Thanks
EDIT-1: Entire writexml Method
public void writexml(xmldatalist XMLList, variables GlobalVars)
{
XmlWriterSettings settings = new XmlWriterSettings
{
Indent = true,
IndentChars = "\t",
NewLineChars = Environment.NewLine,
NewLineHandling = NewLineHandling.Replace,
Encoding = new UTF8Encoding(false)
};
string DesktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
string FileExtension = ".xml";
string PathString = Path.Combine(DesktopFolder, "XML");
System.IO.Directory.CreateDirectory(PathString);
foreach (List<xmldata> i in XMLList.XMLArrayList)
{
int m = 0;
foreach (var x in i)
{
string XMLFilename = System.IO.Path.GetFileNameWithoutExtension(x.xml_filename);
GlobalVars.FullPath = Path.Combine(PathString, XMLFilename + FileExtension);
if (!File.Exists(GlobalVars.FullPath))
{
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement("JMF",
new XAttribute("SenderID", "InkZone-Controller"),
new XAttribute("Version", "1.2"),
new XElement("Command",
new XAttribute("ID", "cmd.00695"),
new XAttribute("Type", "Resource"),
new XElement("ResourceCmdParams",
new XAttribute("ResourceName", "InkZoneProfile"),
new XAttribute("JobID", "K_41"),
new XElement("InkZoneProfile",
new XAttribute("ID", "r0013"),
new XAttribute("Class", "Parameter"),
new XAttribute("Locked", "False"),
new XAttribute("Status", "Available"),
new XAttribute("PartIDKeys", "SignatureName SheetName Side Separation"),
new XAttribute("DescriptiveName", "Schieberwerte von DI"),
new XAttribute("ZoneWidth", "32"),
new XElement("InkZoneProfile",
new XAttribute("SignatureName", "SIG1"),
new XElement("InkZoneProfile",
new XAttribute("Locked", "false"),
new XAttribute("SheetName", "S1"),
new XElement("InkZoneProfile",
new XAttribute("Side", "Front"),
new XElement("ColorPoolClass",
new XAttribute("Class", "Parameter"),
new XAttribute("DescriptiveName", "Colors for the job"),
new XAttribute("Status", "Available")
)))))))));
doc.Save(GlobalVars.FullPath);
XDocument XmlDoc = new XDocument();
XmlDoc = XDocument.Load(GlobalVars.FullPath);
XElement InkZonePath = XmlDoc.Root.Descendants("InkZoneProfile").Where(z => (string)z.Attribute("Side") == "Front").SingleOrDefault();
if (InkZonePath != null)
{
InkZonePath.AddAfterSelf(new XElement("InkZoneProfile",
new XAttribute("Separation", x.colorname),
new XAttribute("ZoneSettingsX", x.colorvalues)));
}
XmlDoc.Save(GlobalVars.FullPath);
}//Closing !FileExists
}//Closing inner foreach
}//Closing outer foreach
}//Closing writexml method
The problem with your current code is here : Element("JMF").Elements("InkZoneProfile") Since InkZoneProfile is not a direct child of JMF it will not return anything. Use Descendants instead.
Check difference between Elements & Descendants.
This should give you correct result:-
XElement InkZonePath = xdoc.Element("JMF").Descendants("InkZoneProfile")
.SingleOrDefault(z => (string)z.Attribute("Side") == "Front")
After this you can add whatever node you want to add using AddAfterSelf. Also note I have used SingleOrDefault here, but you may get exception if you have multiple matching nodes with this, In that case consider using FirstOrDefault.
Update:
To add new node:-
if (InkZonePath != null)
{
InkZonePath.AddAfterSelf(new XElement("InkZoneProfile",
new XAttribute("Separation", "Test"),
new XAttribute("ZoneSettingsX", "Test2")));
}
//Save XDocument
xdoc.Save(#"C:\Foo.xml");
You need to use Descendants method instead Elements:
XElement InkZonePath = XmlDoc.Root.Descendants("InkZoneProfile").Where(z => (string)z.Attribute("Side") == "Front").SingleOrDefault();
if(InkZonePath !=null)
InkZonePath.AddAfterSelf(new XElement("InkZoneProfile",
new XAttribute("Separation", x.colorname),
new XAttribute("ZoneSettingsX", x.colorvalues)));
you can use Descendants instead.
var node = XmlDoc.Descendants("InkZoneProfile").Where(x=> x.Attribute("Side") !=null && x.Attribute("Side").Value == "Front").FirstorDefault();

How to add elements in an XML file?

How should I add X there in XElement ?
XDocument triggerDocument = new XDocument(
new XDeclaration("1.0", "utf-8", null));
XElement triggerRoot = new XElement("config",
new XElement("maketool-config",
new XElement("hmi", new XElement("Messages",X))));
triggerDocument.Add(triggerRoot);
triggerDocument.Save(Path.Combine(outPath, "_triggers.xml"));
for (int i = 0; i <= events.Count; i++)
{
foreach (var item in events)
{
triggerRoot.Add(new XElement("n",
new XAttribute("page", item.page),
new XAttribute("sequence", item.sequence),
new XAttribute("priority", item.priority),
new XAttribute("errorText", item.errorText)
));
}
}
so it should look like this :
<?xml version="1.0" encoding="utf-8"?>
<config schema ="sdk-hmi.xsd">
<maketool-config>
<hmi>
<messages>
<n page="" sequence="" priority="" errorText="" />
<n page="" sequence="" priority="" errorText="" />
<n page="" sequence="" priority="" errorText="" />
<n page="" sequence="" priority="" errorText="" />
<n page="" sequence="" priority="" errorText="" />
</messages>
</hmi>
</maketool-config>
</config>
You can pass an XElement[] or IEnumerable<XElement> to XElement's constructor:
var messages = events.Select(item => new XElement("n",
new XAttribute("page", item.page),
new XAttribute("sequence", item.sequence),
new XAttribute("priority", item.priority),
new XAttribute("errorText", item.errorText)
));
XDocument triggerDocument = new XDocument(
new XDeclaration("1.0", "utf-8", null));
XElement triggerRoot = new XElement("config",
new XElement("maketool-config",
new XElement("hmi",
new XElement("Messages", messages))) // <<<--- This is the important part.
);
triggerDocument.Add(triggerRoot);
You can try this:
XDocument triggerDocument = new XDocument(
new XDeclaration("1.0", "utf-8", null));
XElement triggerRoot = new XElement("config",
new XElement("maketool-config",
new XElement("hmi", new XElement("Messages"))));
triggerDocument.Add(triggerRoot);
XElement msgNode = triggerRoot.Elements("Messages")
.SingleOrDefault();
if (msgNode != null)
{
foreach (var item in events)
{
msgNode.Add(new XElement("n",
new XAttribute("page", item.page),
new XAttribute("sequence", item.sequence),
new XAttribute("priority", item.priority),
new XAttribute("errorText", item.errorText)
));
}
}
May this will help to add nodes...
//file name
string filename = #"d:\temp\XMLFile2.xml";
//create new instance of XmlDocument
XmlDocument doc = new XmlDocument();
//load from file
doc.Load(filename);
//create node and add value
XmlNode node = doc.CreateNode(XmlNodeType.Element, "Genre_Genre_Country", null);
node.InnerText = "this is new node";
//add to elements collection
doc.DocumentElement.AppendChild(node);
//save back
doc.Save(filename);

Save a Dictionary<int, List<Object>> data to XML file using LINQ

I want to write a Dictionary<int, List<Object>> data to XML file. I tried below code:
Dictionary<int, List<Author>> _empdata = new Dictionary<int, List<Author>>();
List<Author> _author1 = new List<Author> { new Author() { id = 1, name = "Tom", age = 25 } };
List<Author> _author2 = new List<Author> { new Author() { id = 2, name = "Jerry", age = 15 } };
_empdata.Add(1, _author1);
_empdata.Add(2, _author2);
string fileName = "Author_" + string.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}", DateTime.Now);
string filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName) + ".xml";
XElement elem = new XElement("StackOverflow");
foreach (KeyValuePair<int,List<Author>> pair in _empdata)
{
elem = new XElement("AUTHORDATA",
from item in pair.Value
select new XElement("AUTHOR",
new XElement("ID", item.id),
new XElement("NAME", item.name),
new XElement("AGE", item.age)
));
}
elem.Save(filePath);
My expected output is:
<AUTHORDATA>
<AUTHOR>
<ID>1</ID>
<NAME>Tom</NAME>
<AGE>25</AGE>
</AUTHOR>
<AUTHOR>
<ID>2</ID>
<NAME>Jerry</NAME>
<AGE>15</AGE>
</AUTHOR>
</AUTHORDATA>
But,I am getting below records in XML file:
<AUTHORDATA>
<AUTHOR>
<ID>2</ID>
<NAME>Jerry</NAME>
<AGE>15</AGE>
</AUTHOR>
</AUTHORDATA>
It is only writing the last List record in XML file every time. How can I fix this ? Note: The format of the XML file will be like above.
Any help is appreciated.
[EDIT] Awww sorry, I was misunderstanding your request:
XElement ad = new XElement("AUTHORDATA");
XElement elem = new XElement("StackOverflow", ad);
foreach (KeyValuePair<int, List<Author>> pair in _empdata)
{
ad.Add(new XElement("AUTHORDATA",
from item in pair.Value
select new XElement("AUTHOR",
new XElement("ID", item.id),
new XElement("NAME", item.name),
new XElement("AGE", item.age)
));
}
elem.Save(filePath);
You need to add node created in loop to AUTHORDATA node:
var authorData = new XElement("AUTHORDATA");
var root = new XElement("StackOverflow", authorData);
foreach (KeyValuePair<int,List<Author>> pair in _empdata)
{
authorData.Add(
from item in pair.Value
select new XElement("AUTHOR",
new XElement("ID", item.id),
new XElement("NAME", item.name),
new XElement("AGE", item.age)
));
}
root.Save(filePath);

How to create a XML file using XDocument and LINQ in C#?

I have a three List in c# ,the variable names are l_lstData1,l_lstData2,l_lstData3
The File Structure is
<FileDetails>
<Date FileModified="29/04/2010 12:34:02" />
<Data Name="Data_1" DataList="India" Level="2" />
<Data Name="Data_2" DataList="chennai" Level="2" />
<Data Name="Data_3" DataList="hyderabad" Level="2" />
<Data Name="Data_4" DataList="calcutta" Level="2" />
<Data Name="Data_5" DataList="vijayawada" Level="1" />
<Data Name="Data_6" DataList="cochin" Level="1" />
<Data Name="Data_7" DataList="madurai" Level="0" />
<Data Name="Data_8" DataList="trichy" Level="0" />
</FileDetails>
The Values od 3 Lists are as follows :
l_lstData1[0] = "India";l_lstData1[1] = "chennai";l_lstData1[2] = "hyderabad";
l_lstData1[3] = "calcutta";
so the level attribute of the above XML(element : Data) has tha value = "2".
l_lstData2[0] = "vijayawada";l_lstData2[1] = "cochin";
so the level attribute of the above XML(element : Data) has tha value = "1".
l_lstData3[0] = "madurai";l_lstData3[1] = "trichy";
so the level attribute of the above XML(element : Data) has tha value = "0".
How can i create the XML using Xdocument and also using LINQ....Plz revert back me if u have any queries
Here's an alternative to Pramodh's solution, if I've understood it correctly:
// First build up a single list to work with, using an anonymous type
var singleList = l_lstData1.Select(x => new { Value = x, Level = 2})
.Concat(l_lstData2.Select(x => new { Value = x, Level = 1})
.Concat(l_lstData3.Select(x => new { Value = x, Level = 0});
var doc = new XDocument(
new XElement("FileDetails",
new XElement("Date",new XAttribute("FileModified", DateTime.Now)),
singleList.Select((item, index) => new XElement("Data",
new XAttribute("Name", "Data_" + (index + 1)),
new XAttribute("DataList", item.Value),
new XAttribute("Level", item.Level))));
Try like this:
XDocument TEMP = new XDocument(new XElement("FileDetails",
new XElement("Date",new XAttribute("FileModified", DateTime.Now.ToString())),
l_lstData1.Select(l => new XElement("Data",new XAttribute("Name","Data_"+(l_lstData1.IndexOf(l)+1).ToString()),
new XAttribute ("DataList",l.ToString()),
new XAttribute ("Level","Level2"))),
l_lstData2.Select(l => new XElement("Data",new XAttribute("Name","Data_"+(l_lstData2.Count + l_lstData2.IndexOf(l)+1).ToString()),
new XAttribute ("DataList",l.ToString()),
new XAttribute ("Level","Level1"))) ,
l_lstData3.Select(l => new XElement("Data",new XAttribute("Name", "Data_" + (l_lstData3.Count + l_lstData2.Count + l_lstData3.IndexOf(l) + 1).ToString()),
new XAttribute ("DataList",l.ToString()),
new XAttribute ("Level","Level0")))
));
TEMP.Save("TEMP.xml");

Categories

Resources