Case Sensitive Issue with XML
-
Hi, Im trying to do a simple XML Record Lookup using the following code:
string fileName = "Account_Data.xml"; XPathDocument doc = new XPathDocument(fileName); XPathNavigator nav = doc.CreateNavigator(); XPathExpression expr; expr = nav.Compile("/Accounts/Account[FirstName='" + nameTextBox.Text + "']"); XPathNodeIterator iterator = nav.Select(expr); iterator = nav.Select(expr); if (iterator.MoveNext()) { // Record Found } else { // Record Not Found, So Create A New One Here }
It works just fine, but there seem to be a minor bug with it. In the XML file, i already have a record with Latheesan, so when i searched using my search form for "latheesan", it returned 0 results, hense it created a new record. How can i avoid case sensitiveness issues with searching through XML Records? -
Hi, Im trying to do a simple XML Record Lookup using the following code:
string fileName = "Account_Data.xml"; XPathDocument doc = new XPathDocument(fileName); XPathNavigator nav = doc.CreateNavigator(); XPathExpression expr; expr = nav.Compile("/Accounts/Account[FirstName='" + nameTextBox.Text + "']"); XPathNodeIterator iterator = nav.Select(expr); iterator = nav.Select(expr); if (iterator.MoveNext()) { // Record Found } else { // Record Not Found, So Create A New One Here }
It works just fine, but there seem to be a minor bug with it. In the XML file, i already have a record with Latheesan, so when i searched using my search form for "latheesan", it returned 0 results, hense it created a new record. How can i avoid case sensitiveness issues with searching through XML Records?Never done this myself, but I think you can only avoid case sensitiveness by turning both the search string as well as the content of FirstName to either upper or lower case. For the search string you can use the appropriate methods provided by the
String
class. In case of the content of FirstName you'll have to use XPath functions[^].
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook