代码之家  ›  专栏  ›  技术社区  ›  user3784080

获取所有xml属性的列表

  •  2
  • user3784080  · 技术社区  · 8 年前

    我正在进行一个API调用,返回 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调用是动态的,并返回不同的属性。

    2 回复  |  直到 8 年前
        1
  •  3
  •   Mathias R. Jessen    8 年前

    看看 Attributes 财产 XmlElement 所涉对象:

    $myData.Attributes |ForEach-Object {
        'Name: {0}; Value: {1}' -f $_.LocalName,$_.Value
    }
    
        2
  •  2
  •   Martin Brandl    8 年前

    看看 Format-List Get-Member

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