Skip to content

Instantly share code, notes, and snippets.

@minutillo
minutillo / C#_XML_SearchNode
Last active February 5, 2017 20:58
C# ASP.NET XML Search Node
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("~/path/xmlfile.xml"));
XmlElement root = xmldoc.DocumentElement;
XmlNode node = root.SelectSingleNode("<node1>/<node2>[../<node3>='" + <text to find> + "']");
String html = "";
html += node.InnerText + "<br />";
@minutillo
minutillo / C#_XML_SearchEntireDocument
Last active February 5, 2017 20:58
C# ASP.NET XML Search Entire Document
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("~/filepath/filename.xml"));
XmlElement root = xmldoc.DocumentElement;
XmlNodeList nodes = root.SelectNodes("//*[contains(text(), '<text to find>')]");
String html = "";
foreach (XmlNode node in nodes)
{
html += node.SelectSingleNode.InnerText + "<br />";
}