我有一个具有这种结构的 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/