Last post Feb 04, 2008 02:37 PM by gunteman
Feb 03, 2008 01:22 PM|ricc|LINK
Hi I have the following xPath:
string xPath = "//appSettings/add[@key='" + settingsKey + "']";
however I want to use this query on an xml doc that I do not know the case of each node.
so I my have:
"AppSettings" or "Appsettings" etc
How would I use (translate(.,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ') on the above xPath query?
Feb 03, 2008 01:53 PM|Bonekrusher|LINK
If you dont know the node but you do know the @key attribute you can use:
string xPath = "//@key='" + settingsKey + "'";
Feb 03, 2008 01:53 PM|gunteman|LINK
string xPath = "//appSettings/add[translate(@key,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')='" + settingsKey.ToUpper() + "']";
You could also investigate using the ms:string-compare method.
Feb 03, 2008 04:04 PM|ricc|LINK
Thanks for the replies guys. I do need to use "//appSettings/add" within the xPath, however my problem is that the xml doc I'm search might have
<add key=" ....
or it might be
<Add KEY=" ....
ie I need to make sure the whole thing is case insensitive
Feb 04, 2008 12:34 PM|Bonekrusher|LINK
You can test if you have the element:
<xsl:if test="@key = 12">
<xsl:if test="@Key = 12">
Feb 04, 2008 02:37 PM|gunteman|LINK
In what context are you using the XPath? With an XmlDocument, and Xsl transformation?
If you want to use plain XPath to find elements and attributes case insensitively, you should use something like:
and similar for the attributes (using @*)
If you're using an XmlDocument you can either feed it with a custom XmlReader which makes all names lower or upper case, or use a custom Context
If you're transforming with Xsl, you can add an extension object, through the XslArgumentList
But to be honest, I think that you should not be so forgiving. Wrong case is wrong case.