Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
I have created a form which have two text boxes. txtName and txtJob.
What i did is whenever user enter Name and job in respective boxes,
those Name and Job got saved as xml like this

XML
<!--Name job Configuration-->
<NameJobConfig>
  <Name>NameFromTextBox</Name>
  <job>JobFromTextBox </job>
</NameJobConfig>


i saved this xml as string in a string variable msgText.

now i want to loop through the 'msgText' and find out NameFromTextBox
and JobFromTextBox and display in the respective textboxes.

How do i do it?
Posted
Updated 20-Jan-16 5:08am
v6
Comments
PIEBALDconsult 19-Jan-16 17:40pm    
Don't loop; load the text into an XmlDocument (or similar) and use XPath.
https://msdn.microsoft.com/en-us/library/system.xml.xmldocument.loadxml(v%3Dvs.110).aspx
_Asif_ 20-Jan-16 0:29am    
This is the solution!
[no name] 20-Jan-16 0:44am    
any idea. I have updated the situation again
_Asif_ 20-Jan-16 0:56am    
Its pretty easy, check this http://stackoverflow.com/questions/8299069/using-xpath-to-parse-an-xml-document
PIEBALDconsult 19-Jan-16 18:04pm    
What's with all those apostrophes?

1 solution

C#
XDocument xdoc = XDocument.Parse(xmlData);  

var jobList = (from rec in xdoc.Descendants("NameJobConfig")  
select new  
{  
      Name = rec.Element("Name").Value,  
      Job = rec.Element("job").Value  
}).SingleOrDefault();  

txtName.Text = Convert.ToString(jobList.Name);  
txtJob.Text = Convert.ToString(jobList.Job);


I already got it. Thank you guys for help. I dont know how to close this and accept the solution
 
Share this answer
 
Comments
Graeme_Grant 16-Sep-17 8:06am    
Please don't answer your own question with a solution and then accept it as a valid solution. This is see as REP farming and can get you banned if continued. Update your question instead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900