-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
54 lines (41 loc) · 1.63 KB
/
Program.cs
File metadata and controls
54 lines (41 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.IO;
using System.Net;
using System.Xml;
namespace XmlRead
{
class Program
{
static void Main(string[] args)
{
WebClient webClient = new WebClient();
var imageFolderPath = Path.Combine( Directory.GetCurrentDirectory(), "images");
//var xmlPath = System.IO.Path.GetFullPath("xml-export-2.xml");
var xmlPath = "https://www.meliketatar.com/xml-export";
XmlDocument xml = new XmlDocument();
xml.Load(xmlPath);
int counter = 0;
XmlNodeList xnList = xml.SelectNodes("/Products/Product");
foreach (XmlNode product in xnList)
{
string barcode = "";
var firstVariant = product.SelectNodes("Variants/Variant")[0];
if (firstVariant == null)
barcode = product["ProductBarcode"].InnerText;
else
barcode = firstVariant["VariantBarcode"].InnerText;
XmlNodeList images = product.SelectNodes("Images/*");
for (int i = 0; i < images.Count; i++)
{
string url = images[i].InnerText;
string ext = url.Substring(url.LastIndexOf("."));
string imageName = String.Format("{0}-{1}{2}", barcode, (i + 1).ToString(), ext);
webClient.DownloadFile(url, Path.Combine(imageFolderPath, imageName));
}
counter++;
}
Console.WriteLine("Toplam ürün sayısı = " + counter.ToString());
Console.ReadKey();
}
}
}