获取所有 xml 属性的列表

Get a list of all xml attributes

我正在 API 调用 returns System.Xml.XmlElement 中的值, 但它看起来像这样:

  id                       : 5847538497
  ipAddress                : 192.168.110.1
  status                   : RUNNING
  upgradeStatus            : UPGRADED
  upgradeAvailable         : false

将其保存在局部变量中 myData。如何打印返回的 XML?

的所有属性

如果我输入它就有效:

> Write-Host myData.id
> Write-Host myData.status

但我不知道所有属性,因为 api 调用是动态的并且 returns 不同的属性。

查看 Format-List and the Get-Member cmdlet:

myData | Format-List * -force
myData | Get-Member

看看有问题的 XmlElement 对象上的 Attributes 属性:

$myData.Attributes |ForEach-Object {
    'Name: {0}; Value: {1}' -f $_.LocalName,$_.Value
}