PowerShell select-xml xpath似乎不起作用

时间:2010-11-29 22:39:35

标签: xml sharepoint powershell select-xml

我正在尝试使用select-xml从SharePoint解决方案中根除一些内容。我有一个包含许多功能的解决方案目录,而不是打开每个feature.xml并手动选择功能名称并将它们放在列表中,我希望使用powershellselect-xml

我的尝试是这样的:

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

我什么也没得到,所以我试过了:

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

似乎做了应该做的事情。我得到了解决方案中所有feature.xml文件中每个XML节点的列表。

我尝试了像“// Feature”和“Feature”这样的XPath表达式,但都没有得到任何结果。

在我看来,我的XPath表达式是正确的,但select-xml的行为有点令人困惑。任何人都知道为什么会这样吗?

2 个答案:

答案 0 :(得分:8)

问题可能在于xml命名空间。尝试使用-namespace来获取正确的xpath查询。

通过从feature.xml文件中删除xmlns并运行命令来测试它。

答案 1 :(得分:8)

即使是“默认”命名空间也必须指定给Select-Xml,例如:

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