how to look for a VALUE in an xml document. Not a node.
-
How do i check if a certain value exists? For example, if my document looks like this:
Name1 Active 0 Name2 Active 1
how would i query the document to see if "Name1" exists?
Hi, You can use XPath for this. Below is a code snippet:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"C:\SystemX.xml"); // Loading the xml file stored in C drive.string xPath = "/Systems/systemData[name='Name5']"; // XPath expression to find Name5
XmlNode xmlNode = xmlDoc.SelectSingleNode(xPath); // Find the node.// If not found, show warning.
if (xmlNode == null)
{
MessageBox.Show("Name5 not found");
}Hope this helps. Good luck! :thumbsup:
Integrity is telling myself the truth. And honesty is telling truth to other people. My Blog![^]
-
How do i check if a certain value exists? For example, if my document looks like this:
Name1 Active 0 Name2 Active 1
how would i query the document to see if "Name1" exists?
XmlNode NodeItems = XMLdoc.SelectSingleNode("Systems/Systemdata/name"); NodeItem.InnerText will give you VALUE in particular node