hi i am struggling to get text content out from my xml file as a string.
First, I select a combo box which ha开发者_运维问答s these items:
- 6.00
- 6.10
- 6.20
Secondly, if for example i select "6.00" i will select the string "C:\folder1" 6.10 selects "C:\folder2" 6.20 selects "C:\folder3"
my XML file(path.xml) is as follow:
<main>
<one>C:\folder1</one>
<two>C:\folder2</two>
<three>C:\folder3></three>
</main>
so basically what i need is, to parse this xml file and get the text content. how do i go about doing this? i tried linq parsing:
var prods = from s in
(from c in XElement.Load(@"C:\GUI\path.xml").Descendants("main")
where c.Value.Equals("?????")
select c).Descendants()
select new main()
{
path = s.Value,
};
i am kind of stuck over here because it seems that whenever i use linq parsing, the strings are not differentiated according to the needs of my combo box
Try this linq query:
string elementName = ... ; // see below
var prods = from c in XElement.Load("XMLFile1.xml").Descendants()
where c.Name.LocalName.Equals(elementName)
select c.Value;
Then you just need to convert the numeric value of the ComboBox SelectedIndex to a canonical value ("one", "two", or "three") to match the elements in the XML file. If you only have those three values then a simple switch() statement would do the trick:
string elementName = "one";
switch (comboBox.SelectedIndex)
{
case 2:
elementName = "two";
break;
case 3:
elementName = "three";
break;
}
精彩评论