Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to get the Patient_2 from the <text> tag in a string
my code is
C#
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;
}

but I am not geting id.Please help
Posted
Updated 15-Dec-14 4:00am
v2
Comments
Sinisa Hajnal 15-Dec-14 8:50am    
Your XML is not actually xml. You have image tag, but patient_2 is not within any tag.
Tomas Takac 15-Dec-14 10:01am    
The post was a mess. But the XML was there... hidden in translation. :)
jaket-cp 15-Dec-14 10:36am    
what is the value of notificationContent?

1 solution

Learn using XPath - http://msdn.microsoft.com/en-us/library/ms256115(v=vs.110).aspx[^]
C#
XmlNode node = doc.DocumentElement.SelectsingleNode("toast/text");
 
Share this answer
 
Comments
Sinisa Hajnal 16-Dec-14 2:20am    
Good solution. Just a note: if every such node is needed, use XmlNodeList and doc.DocumentElement.SelectNodes(xpath)

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