Select-Xml Cmldet for PSCX 1.1

We have a new cmdlet coming in PSCX 1.1 (due out in mid February) that is pretty darn handy when you need to query some XML using XPath especially if that XML uses namespaces.  In the past, I have blogged about how to do this.  The PowerShell script looks like this:
PoSH> $lua = [xml](get-content app.exe.0.dat.xml)
PoSH> $nsmgr = new-object Xml.XmlNamespaceManager($lua.PSBase.NameTable)
PoSH> $nsmgr.AddNamespace("avrf", "Application Verifier")
PoSH> $errors = $lua.SelectNodes("//avrf:logEntry[@Severity = ‘Error’]", $nsmgr)
PoSH> $errors | Measure-Object
However with this new cmdlet, courtesy of Mark Maier, you could simplify this to:
PoSH> Select-Xml add.exe.0.dat.xml -XPath "//avrf:logEntry[@Severity = ‘Error’]" -Namespace "avrf=Application Verifier"
Note that -Namespace actually takes an array of prefix;namespace strings.  Also note that even for the default namespace you must supply a prefix (e.g. dns) and use that namespace prefix in your xpath queries (e.g. //dns:HintPath).  I love tools that make me more productive!
This entry was posted in PSCX. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s