Ejemplo n.º 1
0
        public void Convert_text_with_newlines_to_node_with_text_with_newlines()
        {
            var csv = "Id;Description" + Environment.NewLine +
                      @"2;""Wunderschön!

Was soll ich sagen?

Einfach toll!!!""";
            var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<Root>
  <cell>
    <Description />
  </cell>
</Root>";

            File.WriteAllText("tmp.csv", csv);
            File.WriteAllText("tmp.xml", xml);
            var xmlResult = new CsvToXmlConverter(_options).Process().First();

            Console.WriteLine(xmlResult);
            var expected = @"<Description>Wunderschön!

Was soll ich sagen?

Einfach toll!!!</Description>";

            Assert.That(xmlResult.ToString(), Is.StringContaining(expected));
            xmlResult.Save("result.xml");
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            if (args.Length != 2) {
                Console.WriteLine("Need 2 args: schema file and csv file");
                return;
            }

            var xmlTemplateFile = new FileInfo(args[0]);
            var csvDataFile = new FileInfo(args[1]);
            var destination = $"xml_{SafeName(xmlTemplateFile)}_{SafeName(csvDataFile)}";
            Directory.CreateDirectory(destination);
            Console.WriteLine($"Using: {xmlTemplateFile}");
            Console.WriteLine($"Data : {csvDataFile}");
            Console.WriteLine($"Dest.: {destination}");

            var converter = new CsvToXmlConverter(xmlTemplateFile);
            var result = converter.Process(csvDataFile.FullName);

            var counter = 1;
            foreach (var cpXml in result) {
                var contents = cpXml.ToString();
                contents = Regex.Replace(contents, NewLineWithZeroOrMoreSpaces, "")
                    .Replace("</Street><StreetNo>", "</Street> <StreetNo>")
                    .Replace("</ZipCode><Town>", "</ZipCode> <Town>")
                    .Replace("</GeoLatitude><GeoLongitude>", "</GeoLatitude>&#x20;&#x20;<GeoLongitude>")
                    .Replace("><Fkk", ">&#x20;&#x20;<Fkk")
                    .Replace(" lt. Bewertung von ", PS + "lt. Bewertung von" + PS)
                    .Replace("&amp;#x9;", "&#x9;");
                contents = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + contents;
                File.WriteAllText(Path.Combine(destination, counter + ".xml"), contents);
                counter++;
            }
        }
Ejemplo n.º 3
0
 public void Convert_columns_with_value_and_href_to_correct_xml_nodes()
 {
     var csv = "Spalte;NochEine" + Environment.NewLine + "Wert;bild.ai";
     var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
     <Root>
     <cell><Spalte /><NochEine /></cell>
     </Root>";
     File.WriteAllText("tmp.csv", csv);
     var fileName = new FileInfo("tmp.csv").ToString();
     var xmlResult = new CsvToXmlConverter(xml).Process(fileName).First().ToString();
     Console.WriteLine(xmlResult);
     Assert.That(xmlResult, Is.StringContaining("<Spalte>Wert</Spalte>"));
     Assert.That(xmlResult, Is.StringContaining("<NochEine href=\"file://Bilder/bild.ai\" />"));
 }
Ejemplo n.º 4
0
        public void Convert_column_to_text_node_from_xml_file()
        {
            var csv = "Spalte" + Environment.NewLine + "Wert";
            var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<Root>
<cell><Spalte /></cell>
</Root>";

            File.WriteAllText("tmp.csv", csv);
            File.WriteAllText("tmp.xml", xml);
            var xmlResult = new CsvToXmlConverter(_options).Process().First().ToString();

            Console.WriteLine(xmlResult);
            Assert.That(xmlResult, Is.StringContaining("<Spalte>Wert</Spalte>"));
        }
Ejemplo n.º 5
0
        public void Convert_image_column_value_to_href_attribute_in_xml()
        {
            var csv = "Spalte" + Environment.NewLine + "Bilder-Layout/Wert.ai";
            var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<Root>
<cell><Spalte /></cell>
</Root>";

            File.WriteAllText("tmp.csv", csv);
            File.WriteAllText("tmp.xml", xml);
            var xmlResult = new CsvToXmlConverter(_options).Process().First().ToString();

            Console.WriteLine(xmlResult);
            Assert.That(xmlResult, Is.StringContaining("<Spalte href=\"file:///c:/Bilder-Layout/Wert.ai\" />"));
        }
Ejemplo n.º 6
0
        public void Convert_columns_with_value_and_href_to_correct_xml_nodes()
        {
            var csv = "Spalte;NochEine" + Environment.NewLine + "Wert;Bilder-Layout/bild.ai";
            var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<Root>
<cell><Spalte /><NochEine /></cell>
</Root>";

            File.WriteAllText("tmp.csv", csv);
            File.WriteAllText("tmp.xml", xml);
            var xmlResult = new CsvToXmlConverter(_options).Process().First().ToString();

            Console.WriteLine(xmlResult);
            Assert.That(xmlResult, Is.StringContaining("<Spalte>Wert</Spalte>"));
            Assert.That(xmlResult, Is.StringContaining("<NochEine href=\"file:///c:/Bilder-Layout/bild.ai\" />"));
        }
Ejemplo n.º 7
0
 public void Convert_column_and_neighbor_to_node_with_tabbed_text()
 {
     var csv = "Activity1;Activity1Value" + Environment.NewLine +
               "Schwimmen;55 %";
     var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
     <Root>
       <cell>
     <Activity1></Activity1>
       </cell>
     </Root>";
     File.WriteAllText("tmp.csv", csv);
     File.WriteAllText("tmp.xml", xml);
     var fileName = new FileInfo("tmp.csv").ToString();
     var xmlResult = new CsvToXmlConverter(new FileInfo("tmp.xml")).Process(fileName).First().ToString();
     Console.WriteLine(xmlResult);
     Assert.That(xmlResult, Is.StringContaining("<Activity1>Schwimmen\t55 %</Activity1>"));
 }
Ejemplo n.º 8
0
        public void Convert_column_with_text_and_empty_value_column_to_node_with_text()
        {
            var csv = "Stars;StarsValue" + Environment.NewLine +
                      "noch keine;";
            var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<Root>
  <cell>
    <Stars></Stars>
  </cell>
</Root>";

            File.WriteAllText("tmp.csv", csv);
            File.WriteAllText("tmp.xml", xml);
            var xmlResult = new CsvToXmlConverter(_options).Process().First().ToString();

            Console.WriteLine(xmlResult);
            Assert.That(xmlResult, Is.StringContaining("<Stars>noch keine</Stars>"));
        }
Ejemplo n.º 9
0
        public void Convert_column_and_neighbor_to_node_with_tabbed_text()
        {
            var csv = "Activity1;Activity1Value" + Environment.NewLine +
                      "Schwimmen;55 %";
            var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<Root>
  <cell>
    <Activity1></Activity1>
  </cell>
</Root>";

            File.WriteAllText("tmp.csv", csv);
            File.WriteAllText("tmp.xml", xml);
            var xmlResult = new CsvToXmlConverter(_options).Process().First().ToString();

            Console.WriteLine(xmlResult);
            Assert.That(xmlResult, Is.StringContaining($"<Activity1>Schwimmen{Tab}55 %</Activity1>"));
        }
Ejemplo n.º 10
0
 public void Convert_column_and_value_neighbor_to_nested_node_with_only_value()
 {
     var csv = "Lebensmittelversorgung;LebensmittelversorgungValue" + Environment.NewLine +
               "Lebensmittel am Platz;200 m";
     var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
     <Root>
       <cell>
     <Lebensmittelversorgung></Lebensmittelversorgung>
       </cell>
     </Root>";
     File.WriteAllText("tmp.csv", csv);
     File.WriteAllText("tmp.xml", xml);
     var fileName = new FileInfo("tmp.csv").ToString();
     var xmlResult = new CsvToXmlConverter(new FileInfo("tmp.xml")).Process(fileName).First().ToString();
     Console.WriteLine(xmlResult);
     Assert.That(xmlResult, Is.StringContaining(
         "<Lebensmittelversorgung>Lebensmittel am Platz\t200 m</Lebensmittelversorgung>"));
 }
Ejemplo n.º 11
0
        public void Convert_column_and_value_neighbor_to_nested_node_with_only_value()
        {
            var csv = "Lebensmittelversorgung;LebensmittelversorgungValue" + Environment.NewLine +
                      "Lebensmittel am Platz;200 m";
            var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<Root>
  <cell>
    <Lebensmittelversorgung></Lebensmittelversorgung>
  </cell>
</Root>";

            File.WriteAllText("tmp.csv", csv);
            File.WriteAllText("tmp.xml", xml);
            var xmlResult = new CsvToXmlConverter(_options).Process().First().ToString();

            Console.WriteLine(xmlResult);
            Assert.That(xmlResult, Is.StringContaining(
                            $@"<Lebensmittelversorgung>Lebensmittel am Platz{Tab}200 m</Lebensmittelversorgung>"));
        }
Ejemplo n.º 12
0
        public void Convert_rating_column_to_nested_node_with_graphic_and_value()
        {
            var csv = "RatingAvgSth" + Environment.NewLine +
                      "Bilder-Layout/balken_43.ai";
            var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<Root>
  <cell>
    <RatingAvgSth></RatingAvgSth>
  </cell>
</Root>";

            File.WriteAllText("tmp.csv", csv);
            File.WriteAllText("tmp.xml", xml);
            var xmlResult = new CsvToXmlConverter(_options).Process().First().ToString();

            Console.WriteLine(xmlResult);
            Assert.That(xmlResult, Is.StringContaining(
                            $@"<RatingAvgSthGraphic href=""file:///c:/Bilder-Layout/balken_43.ai"" />{Tab}4,3</RatingAvgSth>"));
        }
Ejemplo n.º 13
0
        private static void Main(string[] args)
        {
            var options = new Options();

            var parserResult = Parser.Default.ParseArguments(() => options, args);

            if (parserResult.Tag == ParserResultType.NotParsed)
            {
                HelpText.RenderUsageText(parserResult);
                return;
            }

            var destination = $"xml_{SafeName(options.XmlTemplateFile)}_{SafeName(options.CsvDataFile)}";

            Directory.CreateDirectory(destination);
            Console.WriteLine($"Template: {options.XmlTemplateFile}");
            Console.WriteLine($"Csv Data: {options.CsvDataFile}");
            Console.WriteLine($"ImageDir: {options.ImagesRootFolder}");
            Console.WriteLine($"  Output: {destination}");

            var converter = new CsvToXmlConverter(options);
            var result    = converter.Process();

            var counter = 1;

            foreach (var cpXml in result)
            {
                var contents = cpXml.ToString();
                contents                       = //Regex.Replace(contents, NewLineWithZeroOrMoreSpaces, "")
                                      contents = Regex.Replace(contents, SpaceBeetweenTags, "><")
                                                 .Replace("</Street><StreetNo>", "</Street> <StreetNo>")
                                                 .Replace("</ZipCode><Town>", "</ZipCode> <Town>")
                                                 .Replace("</GeoLatitude><GeoLongitude>", "</GeoLatitude>&#x20;&#x20;<GeoLongitude>")
                                                 .Replace("><Fkk", ">&#x20;&#x20;<Fkk")
                                                 .Replace(" lt. Bewertung von ", PS + "lt. Bewertung von" + PS)
                                                 .Replace("&amp;#x9;", "&#x9;");
                contents = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + contents;
                File.WriteAllText(Path.Combine(destination, counter + ".xml"), contents);
                counter++;
            }
        }
Ejemplo n.º 14
0
        public void Convert_column_and_image_neighbor_to_nested_node_with_value_and_href()
        {
            var csv = "Lebensmittelversorgung;LebensmittelversorgungValue" + Environment.NewLine +
                      "Lebensmittel am Platz;/Bilder-Layout/Yes.ai";
            var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<Root>
  <cell>
    <Lebensmittelversorgung>
      Lebensmittel am Platz
      <Lebensmittelversorgung href=""file:///c:/some-other-path/Yes.ai"" />
    </Lebensmittelversorgung>
  </cell>
</Root>";

            File.WriteAllText("tmp.csv", csv);
            File.WriteAllText("tmp.xml", xml);
            var xmlResult = new CsvToXmlConverter(_options).Process().First().ToString();

            Console.WriteLine(xmlResult);
            Assert.That(xmlResult, Is.StringContaining(
                            $@"<Lebensmittelversorgung>Lebensmittel am Platz{Tab}<Lebensmittelversorgung " +
                            @"href=""file:///c:/Bilder-Layout/Yes.ai"" /></Lebensmittelversorgung>"));
        }
Ejemplo n.º 15
0
 public void Convert_column_with_text_and_empty_value_column_to_node_with_text()
 {
     var csv = "Stars;StarsValue" + Environment.NewLine +
               "noch keine;";
     var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
     <Root>
       <cell>
     <Stars></Stars>
       </cell>
     </Root>";
     File.WriteAllText("tmp.csv", csv);
     File.WriteAllText("tmp.xml", xml);
     var fileName = new FileInfo("tmp.csv").ToString();
     var xmlResult = new CsvToXmlConverter(new FileInfo("tmp.xml")).Process(fileName).First().ToString();
     Console.WriteLine(xmlResult);
     Assert.That(xmlResult, Is.StringContaining("<Stars>noch keine</Stars>"));
 }
Ejemplo n.º 16
0
 public void Convert_url_column_value_to_href_attribute_on_node_in_xml()
 {
     var csv = "Spalte" + Environment.NewLine + "Wert.ai";
     var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
     <Root>
     <cell><Spalte /></cell>
     </Root>";
     File.WriteAllText("tmp.csv", csv);
     var fileName = new FileInfo("tmp.csv").ToString();
     var xmlResult = new CsvToXmlConverter(xml).Process(fileName).First().ToString();
     Console.WriteLine(xmlResult);
     Assert.That(xmlResult, Is.StringContaining("<Spalte href=\"file://Bilder/Wert.ai\" />"));
 }
Ejemplo n.º 17
0
 public void Convert_column_to_text_node_from_xml_file()
 {
     var csv = "Spalte" + Environment.NewLine + "Wert";
     var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
     <Root>
     <cell><Spalte /></cell>
     </Root>";
     File.WriteAllText("tmp.csv", csv);
     File.WriteAllText("tmp.xml", xml);
     var fileName = new FileInfo("tmp.csv").ToString();
     var xmlResult = new CsvToXmlConverter(new FileInfo("tmp.xml")).Process(fileName).First().ToString();
     Console.WriteLine(xmlResult);
     Assert.That(xmlResult, Is.StringContaining("<Spalte>Wert</Spalte>"));
 }
Ejemplo n.º 18
0
 public void Convert_rating_column_to_nested_node_with_graphic_and_value()
 {
     var csv = "RatingAvgSth" + Environment.NewLine +
               "balken_43.ai";
     var xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
     <Root>
       <cell>
     <RatingAvgSth></RatingAvgSth>
       </cell>
     </Root>";
     File.WriteAllText("tmp.csv", csv);
     File.WriteAllText("tmp.xml", xml);
     var fileName = new FileInfo("tmp.csv").ToString();
     var xmlResult = new CsvToXmlConverter(new FileInfo("tmp.xml")).Process(fileName).First().ToString();
     Console.WriteLine(xmlResult);
     Assert.That(xmlResult,
         Is.StringContaining(@"<RatingAvgSthGraphic href=""file://Bilder/balken_43.ai"" />4,3</RatingAvgSth>"));
 }