Sudarvizhi J

Sudarvizhi J

  • NA
  • 101
  • 23.9k

How to read xml from string variable with particular tag

May 18 2018 4:42 AM
we have to use some code for single root value, but we need multiple root elements and particular tag name to read data.
We have to read xml string with particular tag name. Please advise ASAP 
Here is my code we have to use single root value its working fine,
 
string xmlString = "<data><Date>5/15/2018</Date><Name>test test</Name><Course>Storyboarding</Course></data>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString);
XmlNodeList nodes = doc.DocumentElement.SelectNodes("//data");
StringBuilder yourString = new StringBuilder();
foreach (XmlNode node in nodes)
{
yourString.Append("Date:" + node["Date"].InnerText + "<br />");
yourString.Append("Course:" + node["Course"].InnerText + ",");
}
PlaceHolder1.Controls.Add(new LiteralControl(yourString.ToString()));
 

Answers (1)