César Goulart

César Goulart

  • NA
  • 46
  • 2.7k

conecting c# to xml

Feb 9 2020 5:22 PM
Hi, 
I have this code: 
 
 and i want the informatiom that i give. ('Pink') be given by a textbox 
 
How can i do it? thanks 
 
  1. private void button1_Click(object sender, EventArgs e)  
  2. {  
  3.     XDocument doc = XDocument.Load(@"C:\Work\stores.xml");  
  4.   
  5.     var xpath = "//store/Color[text() ='Pink']";  
  6.   
  7.     var result = ((IEnumerable)doc.XPathEvaluate(xpath)).Cast<XElement>().FirstOrDefault();  
  8.     textBox1.Text = result.Value;  
  9.   
  10.   
  11.   
  12.   
  13. }  
 

Answers (2)