gpt4 book ai didi

xml - PowerShell:检索特定的内部 XML 元素

转载 作者:数据小太阳 更新时间:2023-10-29 02:50:41 25 4
gpt4 key购买 nike

我有一个具有这种结构的 XML 文档:

<Fruits>
<Fruit>
<Code>1</Code>
<Name>Apple</Name>
</Fruit>
</Fruits>

获得 <Fruit> 的最佳方法是什么? PowerShell 1 代码中的代码(或任何其他字段)元素?(不是 XPath,因为它仅在 PowerShell 2 中受支持)

谢谢!

最佳答案

您可以像 Posh V1 中的对象一样访问节点

$xml = [xml]"<Fruits>
<Fruit>
<Code>1</Code>
<Name>Apple</Name>
</Fruit>
<Fruit>
<Code>2</Code>
<Name>Orange</Name>
</Fruit>
</Fruits>"
$orange = $xml.Fruits.Fruit | ? { [int]$_.Code -eq 2 }

关于xml - PowerShell:检索特定的内部 XML 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2911368/

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