gpt4 book ai didi

.net - 使用powershell获取xml文件的父节点的直接子节点

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

我有一个如下所示的xml文件

 <ParentNode>
<childnode1>
<Name string="Code1"/>
</childnode1>

<childnode2>
<Name string="Code2"/>
</childnode2>
<childnode3>
<Name string="Code3"/>
</childnode3>
</ParentNode>

我如何使用Powershell打印ParentNode的所有子节点

我尝试通过使用给定的代码
foreach($child in $xmlfile.ParentNode)
{
Write-Host $child
}

它应该打印
childnode1
childnode2
childnode3

最佳答案

PS>[xml]$x=gc c:\temp\xml.xml    
PS>$x.ParentNode

或者也许你想要:
PS>$x.ParentNode |gm -MemberType property |select -expand name     
childnode1
childnode2
childnode3

关于.net - 使用powershell获取xml文件的父节点的直接子节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22786285/

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