[英]How to read specific XML attributes dynamically in PowerShell from a different xml nodes
I have this following XML that I need to read the attributes dynamically however I am stuck in finding the correct way to do it in PS:我有以下 XML ,我需要动态读取属性,但是我一直在寻找正确的方法来在 PS 中执行此操作:
<DataGroups>
<Category1 Identifier="Project789">
<Category2 Identifier="Project234">
<SimpleCategory56 Identifier="Project56">
......
</DataGroups>
I have tried the following till now which works however how do I do this dynamically??到目前为止,我已经尝试了以下方法,但是我如何动态地做到这一点?
$xml = [xml](get-content $Path)
$test = $xml.DataGroups.Category1.Identifier
I have also tried doing something this:我也尝试过这样做:
$xml = [xml](get-content $Path)
Select-Xml -Xml $xml -XPath "//Category1/@Identifier"
but then I am getting somwthing cryptic like the following:但后来我变得像下面这样神秘:
Node Path Pattern
---- ---- -------
Identifier InputStream //Category1/@Identifier
You were on the right track.你走在正确的轨道上。 You had to simply try this in the Select-Xml
:您必须在Select-Xml
中简单地尝试一下:
$xml = [xml](get-content $Path)
(Select-Xml -Xml $xml -XPath "//./@Identifier").Node.Value
Please try and let me know.请尝试让我知道。 It should return它应该返回
Project789
Project234
Project56
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.