使用2"值解析XML"

时间:2015-07-28 12:08:38

标签: xml powershell

我尝试从像这样的XML中选择一个值

<article>
  <attachments/>
  <technical>
    <feature classification="ETIM 5.0" code="EF000889" language="pl" value="EV000074">
      <name>Some name</name>
      <value>1234</value>
    </feature>
    <feature classification="ETIM 5.0" code="EF000881" language="pl">
      <name>Some name</name>
      <value>345</value>
      <unit>A</unit>
    </feature>
  </technical>
</article>

在powershell中我写道:

[xml]$p = Invoke-WebRequest -Uri 'https://domain.tld/file.xml'
$p.article.technical.feature | select code, value, unit

这项工作几乎完美,但是当一个功能有自己的价值时,我会得到如下数组:

code         value              unit
EF000889     {EV000074, 1234}          
EF000881     345                A

任何人都知道如何获得第二个价值?

1 个答案:

答案 0 :(得分:0)

will that work for you ?

$p.article.technical.feature |%{ 
    if ($_.value.gettype().fullname -eq "System.Object[]"){$_.value[1]}          
    else{$_.value}
 }