Advertisement
Guest User

Coucou

a guest
Nov 24th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml;
  7. using System.IO;
  8. using System.Xml.Linq;
  9.  
  10.  
  11. namespace ConvertionCsvToXml
  12. {
  13.     class Program
  14.     {
  15.         private static void Main(string[] args)  
  16.         {
  17.             string[] lines = File.ReadAllLines(@"C:\CSV-TO-XML\CSVFile.csv");
  18.            
  19.             XElement xml = new XElement("Tags",
  20.                 from str in lines
  21.                
  22.                 let columns = str.Split(';') + str.Replace("\"\"\"", "\"")  /*+ str.Replace("\n", "") /*+ str.Replace('"""','"')*/
  23.                 select new XElement("Tag", new XAttribute("name", columns[0]), new XAttribute("path", ""), new XAttribute("type", "OPC"),
  24.  
  25.                         new XElement("Property", new XAttribute("name", "Tooltip"), columns[13]),
  26.                         new XElement("Property", new XAttribute("name", "Datatype"), columns[2]),
  27.                         new XElement("Property", new XAttribute("name", "Value"), columns[1]),
  28.                         new XElement("Property", new XAttribute("name", "OPCServer"), columns[3]),
  29.                         new XElement("Property", new XAttribute("name", "OPCItemPath"), columns[4]),
  30.                         new XElement("Property", new XAttribute("name", "Scalemode"), columns[5]),
  31.                         new XElement("Property", new XAttribute("name", "RawLow"), columns[6]),
  32.                         new XElement("Property", new XAttribute("name", "RawHigh"), columns[7]),
  33.                         new XElement("Property", new XAttribute("name", "ScaledLow"), columns[8]),
  34.                         new XElement("Property", new XAttribute("name", "ScaledHigh"), columns[9]),
  35.                         new XElement("Property", new XAttribute("name", "Deadband"), columns[10]),
  36.                         new XElement("Property", new XAttribute("name", "FormatString"), columns[11]),
  37.                         new XElement("Property", new XAttribute("name", "EngUnit"), columns[12]),
  38.                         new XElement("Property", new XAttribute("name", "HistoryEnabled"), columns[14]),
  39.                         new XElement("Property", new XAttribute("name", "HistoricalDeadband"), columns[15]),
  40.                        
  41.  
  42.                     )
  43.                 );
  44.  
  45.             xml.Save(@"C:\CSV-TO-XML\XMLFile.xml");
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement