How to escape " in XPATH Expression given to SelectSingleNode() of xmldocument class
-
Hi all, I have the following sample XML file Locale Equivalent of above id string myheader.h The "id" contaims string constants extrcted out of C/C++ source code. and the value contains "LOCALE" contains locale equivalent string. I load the xml document document using the XmDocument.Load( fileName) in C#. Sample code string idvalue = "Some string \"some with in quotes\" other\'s with apostrophee %s"; string path = "/ROOT?STRING[@id = \"" + idvalue + "\"]/LOCALE"; // so as to get the text between LOCALE tag XmlDocument doc = new XmlDocument(); doc.Load(fileName); string str = doc.DocumentElement.SelectSingleNode(path).InnerXml; Howvever the the statement throws an exception because the quotes in the path string is not escaped in XML. SelectSingleNode() takes an XPATH expression. How to escape the quotes in an XPATH expression so that the last statement works correctly. The last expression is a problem only when their is a " in id attribute, since the attribute value is enclosed in quotes in Xpath. for id attribute values with no quotes takes me correctly to the text betwen LOCALE tag I tried encoding the " in variable idvalue to " in XPATH, still no success The XML is successfully validated internally aginst a DTD. The XML file contains ", ', &, <, > in their encoded form. Any solutions to offer Regards, Ajith Regards, Ajith