XPath Doubt
-
Hi all, I have the following sample XML file Locale Equivalent of above id string I load the xml document document using the XmDocument.Load( fileName) in C#. Sample code string idvalue = "%s\"Hello\'s World\""; 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 The XML is successfully validated internally aginst a DTD. The XML file contains ", ', &, <, > in their encoded form. Any solutions to offer Regards, Ajith