Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
768 views
in Technique[技术] by (71.8m points)

xml parsing - How to fetch an attribute value from xml using powershell?

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

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"/>

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...