开发者

PowerShell select-xml xpath doesn't seem to work

I'm trying to use select-xml to root out a few things from a SharePoint solution. I have a solution directory that contains a number of features, and rather than open each feature.xml and select names of features by hand and put them in a list, I was hoping to do the开发者_如何学编程 equivalent using powershell and select-xml.

My attempt went something like this:

ls -recurse -filter feature.xml | select-xml "/Feature"

and I got nothing, so I tried this:

ls -recurse -filter feature.xml | select-xml "//*"

which seemed to do what it was supposed to do. I got a list of every XML node in all the feature.xml files in my solution.

I tried XPath expressions like "//Feature" and "Feature", none of which got any results.

It seems to me that my XPath expressions are right, but the behavior of select-xml is a bit bewildering. Anyone know why this might be happening?


Even a "default" namespace has to be specified to Select-Xml e.g.:

$ns = @{dns = 'http://schemas.microsoft.com/sharepoint/'}
ls . -r feature.xml | Select-Xml '//dns:Feature' -Namespace $ns


Maybe the issue is with the xml namespace. Try using the -namespace to get the correct xpath query.

Test this by removing the xmlns from a feature.xml file and running your command.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜