如何使用powershell从xml中获取属性值? [英] How to fetch an attribute value from xml using powershell?

查看:33
本文介绍了如何使用powershell从xml中获取属性值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a list of XML files, from which I have to get the string after a particular line.

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

In the files, I need to look for a tag Event and get the attribute value DLLRoutine. e.g. the tag would look something like below ...

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

我只需要获取 Dllroutine 值.如何使用 PowerShell 执行此操作?

I just need to get Dllroutine values. How to do it using PowerShell?

推荐答案

假设您的 XML 结构类似于:

Assuming your XML structure is something similar to:

$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从xml中获取属性值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆