Last week I managed to write few short posts for PowerShell Magazine. It was whole series about XPath. You can think of it as an extension to my earlier post about case-insensitive Select-Xml. And I can’t express enough how different (read: better) this experience was from writing anything for my own blog. Having second pair of eyes (with healthy amount of criticism) made huge difference in the final “product”.
PowerShell is not case sensitive (most of the time). There are two situation when it is: you explicitly request it (e.g. using operators like –cmatch) or we depend on something where there is no easy way to turn it off. Select-Xml is using XPath and falls in the second category. Whenever I need to query large XML file I prefer to start with more general queries, and there is very few things more frustrating than being forced to remember case of e.g. attribute names. There are two options to go about it.
First of all we can do it easy way: change case of the whole string that defines XML, and be sure, that everything is either lower or upper case. Problem with this approach is the fact, that result we get back is different from original, and we are bit “stuck” with “broken” XML.
Second option is to use XPath own tools to get similar results, and has advantage of getting “proper” XML data back. Using Select-Xml also enables modifying XML and saving under different name.