One-Liner: Case-Insensitive XML Queries

I'm a one-trick pony with XML.  I use $xml.SelectNodes("//name[@attribute='value']") and permutations thereof.  However, XML's SelectNodes() and SelectSingleNode() methods are case-sensitive. 

My coworker Keith Munson found this tidbit:

 $xml.SelectNodes("//element[translate(@AttributeName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') ='AttributeValue']")

This will return

<element AttributeName="attributevalue" />

as well as

<element AttributeName="AttributeValue" />

But it won't work for

<Element AttributeName="AttributeValue" />


<element attributename="AttributeValue" />

Oh, well, it's a start.

Comments (0)

Skip to main content