G
Guest
I have an XML file which have nodes that contain filepaths,
e.g.<path>c:\SomeDirectory\SomeFile.txt</path>
I'm using an XmlDocument and XPath query to try and find a node
XmlDocument doc = new XmlDocument();
doc.LoadXml(File.ReadAllText(xmlFilePath));
string somePath = @"c:\SomeDirectory\SomeFile.txt";
string query = "node1/node2[Path='" + somePath + "']";
XmlNodeList nodes = doc.SelectNodes(query);
The problem is, query becomes
"node1/node2[Path='c:\\SomeDirectory\\SomeFile.txt']" (Note the double quotes
due to the escaping of the backslashes). Obviously this doesn't match the XML
node in question. How do I work around this? (I don't want to use double
backslashes in the XML file.)
e.g.<path>c:\SomeDirectory\SomeFile.txt</path>
I'm using an XmlDocument and XPath query to try and find a node
XmlDocument doc = new XmlDocument();
doc.LoadXml(File.ReadAllText(xmlFilePath));
string somePath = @"c:\SomeDirectory\SomeFile.txt";
string query = "node1/node2[Path='" + somePath + "']";
XmlNodeList nodes = doc.SelectNodes(query);
The problem is, query becomes
"node1/node2[Path='c:\\SomeDirectory\\SomeFile.txt']" (Note the double quotes
due to the escaping of the backslashes). Obviously this doesn't match the XML
node in question. How do I work around this? (I don't want to use double
backslashes in the XML file.)