Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml;
- using System.IO;
- using System.Xml.Linq;
- namespace ConvertionCsvToXml
- {
- class Program
- {
- private static void Main(string[] args)
- {
- string[] lines = File.ReadAllLines(@"C:\CSV-TO-XML\CSVFile.csv");
- XElement xml = new XElement("Tags",
- from str in lines
- let columns = str.Split(';') + str.Replace("\"\"\"", "\"") /*+ str.Replace("\n", "") /*+ str.Replace('"""','"')*/
- select new XElement("Tag", new XAttribute("name", columns[0]), new XAttribute("path", ""), new XAttribute("type", "OPC"),
- new XElement("Property", new XAttribute("name", "Tooltip"), columns[13]),
- new XElement("Property", new XAttribute("name", "Datatype"), columns[2]),
- new XElement("Property", new XAttribute("name", "Value"), columns[1]),
- new XElement("Property", new XAttribute("name", "OPCServer"), columns[3]),
- new XElement("Property", new XAttribute("name", "OPCItemPath"), columns[4]),
- new XElement("Property", new XAttribute("name", "Scalemode"), columns[5]),
- new XElement("Property", new XAttribute("name", "RawLow"), columns[6]),
- new XElement("Property", new XAttribute("name", "RawHigh"), columns[7]),
- new XElement("Property", new XAttribute("name", "ScaledLow"), columns[8]),
- new XElement("Property", new XAttribute("name", "ScaledHigh"), columns[9]),
- new XElement("Property", new XAttribute("name", "Deadband"), columns[10]),
- new XElement("Property", new XAttribute("name", "FormatString"), columns[11]),
- new XElement("Property", new XAttribute("name", "EngUnit"), columns[12]),
- new XElement("Property", new XAttribute("name", "HistoryEnabled"), columns[14]),
- new XElement("Property", new XAttribute("name", "HistoricalDeadband"), columns[15]),
- )
- );
- xml.Save(@"C:\CSV-TO-XML\XMLFile.xml");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement