PowerShell select-xml xpath 似乎不起作用

发布于 2024-10-04 16:07:09 字数 579 浏览 2 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清醇 2024-10-11 16:07:09

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

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

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
明媚殇 2024-10-11 16:07:09

也许问题出在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文