Parsing XML with 2 "values"

I am trying to fetch a value from XML like this

<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>

      

In powershell, I wrote:

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

      

And it works almost perfect, however, when the function has its own value, I end up with an array like:

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

      

Anyone have an idea how to get the second value?

+3


source to share


1 answer


will this work for you?



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

      

0


source







All Articles