PowerShell select-xml xpath 似乎不起作用
我正在尝试使用 select-xml
从 SharePoint 解决方案中根除一些内容。我有一个包含许多功能的解决方案目录,而不是打开每个 feature.xml
并手动选择功能名称并将它们放入列表中,我希望使用 <代码>powershell 和select-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 的行为有点令人困惑。有人知道为什么会发生这种情况吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使是“默认”命名空间也必须指定给 Select-Xml,例如:
Even a "default" namespace has to be specified to Select-Xml e.g.:
也许问题出在 xml 命名空间上。尝试使用 -namespace 来获取正确的 xpath 查询。
通过从 feature.xml 文件中删除 xmlns 并运行命令来测试这一点。
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.