Solved converting .txt file to .xml file using C#

October 15, 2014 at 05:35:29
Specs: windows
I have a .txt file and i want to convert it into .xml file using c#. The txt file looks like



This is my C# code

String[] data = File.ReadAllLines("TextFile.txt");
XElement root = new XElement("root",
from item in data
select new XElement("Line",item));
while executing this i am getting an output as



but my expected output is



thanks in advance

See More: converting .txt file to .xml file using C#

Report •

October 17, 2014 at 03:59:10
So split your line, and base your XElement on that split?

How To Ask Questions The Smart Way

Report •

October 25, 2014 at 18:02:00
✔ Best Answer
As Razor2.3 stated...

Instead of:

select new XElement("Line",item));


string[] myItem = item.split('=');
select new XElement(myItem[0],myItem[1]));

Obviously you'll get a whole lot of screwed up stuff if a particular line in your text file has more than one "=" in it but if it doesn't then you're home free!

message edited by FBI Agent

Report •

Related Solutions

Ask Question