I am wanting to convert a large amount of xml data near 600mb where i wont no its headers or root nodes I did try the following code but its complaining it does not no its root nodes. What is the most effiecent way of processiing a large file.
using (FileStream fs = new FileStream(@"C:\Projects\csvExport\csvExport\csvExport\bin\VLFLBNM7.xml", FileMode.Open))
{
XmlRootAttribute xRoot = new XmlRootAttribute();
xRoot.ElementName = "ReportDetails";
// xRoot.Namespace = "http://www.cpandl.com";
xRoot.IsNullable = true;
XmlSerializer serializer = new XmlSerializer(typeof(Sequence[]),xRoot);
var data = (Sequence[])serializer.Deserialize(fs);
List<string> list = new List<string>();
foreach (var item in data)
{
List<string> ss = new List<string>();
foreach (var point in item.SourcePath) ss.Add(point.X + "," + point.Y);
list.Add(string.Join(",", ss));
}
File.WriteAllLines(@"C:\Projects\csvExport\csvExport\csvExport\bin\csvFile.csv", list);
}
This code works fine if your XML is having root node with Name "ReportDetails"
Sample XML file for this code to work should be like
<?xml version="1.0"?>
<ReportDetails>
<Sequence>
<SourcePath>
<X>samply x</X>
<Y>xample y</Y>
</SourcePath>
</Sequence>
</ReportDetails>
Your XML is missing "ReportDetails" which you have specified in code
xRoot.ElementName = "ReportDetails";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.