Best method for comparing XML with string



I am looking for the best way to compare XML data with a string. the data is stored in a xml called test.xml, and must be compared with the name descendant, if there is a match more info from the xml must be added to a textbox and picture box.


My ( working ) code:



var xmlDocument = XDocument.Load("test.xml"); // XML koppellen
var key1 = xmlDocument.Descendants("NAME"); // XML filepath
var key2 = xmlDocument.Descendants("TITLE"); // XML titel
var key3 = xmlDocument.Descendants("BRAND"); // XML afbeelding
var key4 = xmlDocument.Descendants("TYPE"); // XML merk
var key5 = xmlDocument.Descendants("SOORT"); // XML type
var key6 = xmlDocument.Descendants("NAAM"); // XML naam

List<string> file = new List<string>();
List<string> title = new List<string>();
List<string> brand = new List<string>();
List<string> type = new List<string>();
List<string> soort = new List<string>();
List<string> naam = new List<string>();

int i = 0;

foreach (var key in key1)
{
file.Add(key.Value.Trim());
}

foreach (var key in key2)
{
title.Add(key.Value.Trim());
}

foreach (var key in key3)
{
brand.Add(key.Value.Trim());
}

foreach (var key in key4)
{
type.Add(key.Value.Trim());
}

foreach (var key in key5)
{
soort.Add(key.Value.Trim());
}

foreach (var key in key6)
{
naam.Add(key.Value.Trim());
}


foreach (var Name in naam)
{
if (textBox3.Text.ToString() == Name.ToString())
{
PDFLocation = file[i].ToString();
pictureBox1.Image = pdfhandler.GetPDFthumbNail(PDFLocation);
textBox4.Text =
title[i].ToString() + "\r\n" +
brand[i].ToString() + "\r\n" +
type[i].ToString() + "\r\n" +
soort[i].ToString() + "\r\n" +
textBox3.Text + "\r\n";
}
i++;
}


]


I think this is not the best way to do it, but cant see a better way....


No comments:

Post a Comment