如何从xml标记读取值 [英] How to read value from xml tag
本文介绍了如何从xml标记读取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我想从< text>获取Patient_2字符串中的标签
我的代码是
Hi I want to get the Patient_2 from the <text> tag in a string
my code is
string xml="<toast launch=\"Patient_2\"><visual><binding template=\"ToastImageAndText01\"><image id=\"1\" src=\"ms-appx:///Assets/Bell.png\"></image><text id=\"1\">Patient_2</text></binding></visual><audio loop=\"true\" src=\"ms-winsoundevent:Notification.Looping.Alarm\" /></toast>";
XDocument doc = XDocument.Parse(notificationContent);
foreach (XElement element in doc.Descendants("text"))
{
var id = element;
}
但是我没有找到id.Please help
but I am not geting id.Please help
推荐答案
学习使用XPath - http://msdn.microsoft.com/en-us/library/ms256115 (v = vs.110).aspx [ ^ ]
Learn using XPath - http://msdn.microsoft.com/en-us/library/ms256115(v=vs.110).aspx[^]
XmlNode node = doc.DocumentElement.SelectsingleNode("toast/text");
这篇关于如何从xml标记读取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文