如何循环通过保存在字符串varibale中的xml并从节点获取数据? [英] how to loop through xml saved in as string varibale and get the data from the node?
问题描述
我创建了一个包含两个文本框的表单。 txtName和txtJob。
我做的是每当用户在相应的框中输入姓名和工作时,
那些姓名和工作被保存为像这样的xml
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
<!--Name job Configuration-->
<NameJobConfig>
<Name>NameFromTextBox</Name>
<job>JobFromTextBox </job>
</NameJobConfig>
i将此xml保存为字符串变量msgText中的字符串。
现在我想循环遍历'msgText'并找出NameFromTextBox
和JobFromTextBox并显示在相应的文本框中。
我该怎么做?
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?
推荐答案
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
这篇关于如何循环通过保存在字符串varibale中的xml并从节点获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!