Last post Jan 21, 2015 09:50 AM by smirnov
Nov 26, 2014 06:48 PM|ma701ss|LINK
I've tried this to search for the word 'apple' within 'DESCRIPTION' of all 'PRODUCT' elements in an xml document:
Dim fruit As XmlNodeList = doc.SelectNodes("//PRODUCT[translate(., 'ABCDEFGHJIKLMNOPQRSTUVWXYZ', 'abcdefghjiklmnopqrstuvwxyz') = contains(DESCRIPTION,'apple')]")
This works however if I change it to for example 'applE' it doesn't.
There are loads of variations on the syntax I've found on Google but it's all a bit confusing.
Any help appreciated.
Nov 28, 2014 03:33 AM|Zhi Lv - MSFT|LINK
As for this issue, here are some similar threads and useful articles. Please refer to them.
XMLDocument SelectNodes: http://forums.asp.net/t/1498407.aspx?XMLDocument+SelectNodes
Using XPath translate() to ignore case in xPath query: http://forums.asp.net/t/1214767.aspx?Using+XPath+translate+to+ignore+case+in+xPath+query
Case-insensitive XPath in .NET: http://blogs.msdn.com/shjin/archive/2005/07/22/442025.aspx
Use XPath to Perform a Case-Insensitive Search with MSXML: http://support.microsoft.com/kb/315719
Dec 03, 2014 04:34 PM|ma701ss|LINK
Thanks but I already found some of those links to get to my solution posted above, particularly the last link which is the same as what I have except I am using "contains". Trouble is it's not working and I could use some help!
Jan 21, 2015 09:50 AM|smirnov|LINK
The right syntax is
doc.SelectNodes("//PRODUCT/DESCRIPTION[contains(translate(., 'ABCDEFGHJIKLMNOPQRSTUVWXYZ','abcdefghjiklmnopqrstuvwxyz'), 'apple')]")
because contains() is used like
and changing to lower case is
fruit = doc.SelectNodes("//PRODUCT/DESCRIPTION[translate(., 'ABCDEFGHJIKLMNOPQRSTUVWXYZ','abcdefghjiklmnopqrstuvwxyz') = 'some apple']")
Complete demo: https://dotnetfiddle.net/kUDTUr