gpt4 book ai didi

powershell - 如何使用Powershell从xml获取属性值?

转载 作者:行者123 更新时间:2023-12-03 10:45:52 24 4
gpt4 key购买 nike

我有一个XML文件列表,我必须从中获取特定行之后的字符串。

在文件中,我需要查找标记Event并获取属性值DLLRoutine
例如标签看起来像下面的样子...

<Event Definition="Validate" DLLPath="" DLLName="Helper.dll" DLLClass="HelpMain" 
DLLRoutine="pgFeatureInfoOnValidate_WriteToRegSelectedFeatures"
InputParameters="pTreeViewFeatureTreeServerOS" RunOnce="no"/>

我只需要获取 Dllroutine值。如何使用PowerShell进行操作?

最佳答案

假设您的XML结构类似于:

$xml = [xml]'
<Events>
<Event Definition="Validate" DLLPath="" DLLName="Helper.dll" DLLClass="HelpMain" DLLRoutine="pgFeatureInfoOnValidate_WriteToRegSelectedFeatures" InputParameters="pTreeViewFeatureTreeServerOS" RunOnce="no"/>
<Event Definition="Validate1" DLLPath="" DLLName="Helper.dll1" DLLClass="HelpMain1" DLLRoutine="pgFeatureInfoOnValidate_WriteToRegSelectedFeatures" InputParameters="pTreeViewFeatureTreeServerOS" RunOnce="no"/>
</Events>
'

#Or get it from a XML file
$xml = [xml](Get-Content $XMLPath)

$xml.Events.Event | Select DLLName

关于powershell - 如何使用Powershell从xml获取属性值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12212452/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com