0

I have XML file which has few nodes. Each node has "Name" attribute. I want to find an XML node based on the value of "Name" attribute. Below is the code that I have written but it is case sensitive.

 XmlDocument xmlDoc = new XmlDocument();
 xmlDoc.Load(file);

 XmlNodeList nodes = xmlDoc.SelectNodes(string.Format("/somevalue/someohtervalue/*[@name = '{0}']", Name));

How can I find the node irrespective of case?

Microsoft Developer
  • 5,229
  • 22
  • 93
  • 142
  • You've used the `xmlreader` tag, but have given no indication of using `XmlReader` in your code. Do you *have* to use XPath? Personally I'd use LINQ to XML with a simple mixture of `Elements`/`Descendants`/`Where`, at which point you can put any logic you like in the filter. I'm sure XPath can be made case-insensitive if necessary, but I prefer to stick to one language where feasible, rather than embedding one in another. – Jon Skeet May 20 '15 at 06:23
  • @JonSkeet Can you please explain in detail. I did not get your point – Microsoft Developer May 20 '15 at 06:35
  • See my solution at following posting : http://stackoverflow.com/questions/30337074/parsing-a-specific-xml-from-api-in-c-sharp/ – jdweng May 20 '15 at 06:36
  • @ChiragFanse: Which part? – Jon Skeet May 20 '15 at 08:08
  • @JonSkeet You have mentioned about XPath. How can I use case-insensitive XPath in above case? – Microsoft Developer May 20 '15 at 09:13
  • Well, you could start by searching in Stack Overflow - http://stackoverflow.com/questions/2893551/case-insensitive-matching-in-xpath for example would work if you don't need to worry about culture-sensitive lowercasing. ("Case-insensitive" isn't as clear an idea as you might expect.) But if your focus is xpath, you should really state that in your question - aside from anything else, an `xpath` tag would be much more appropriate than `xmlreader`... – Jon Skeet May 20 '15 at 09:16

0 Answers0