17

I have XML file with this data

<?xml version="1.0" encoding="windows-1251" ?>
<ValCurs Date="06/06/2012" name="Курби асъор">
 <Valute ID="036">
   <CharCode>AUD</CharCode> 
   <Nominal>1</Nominal> 
   <Name>Доллари Австралия</Name> 
   <Value>4,6430</Value> 
  </Valute>
 <Valute ID="944">
   <CharCode>AZN</CharCode> 
   <Nominal>1</Nominal> 
   <Name>Манати Озарбой&#1207;он</Name> 
   <Value>6,0677</Value> 
  </Valute>
 <Valute ID="826">
   <CharCode>GBP</CharCode> 
   <Nominal>1</Nominal> 
   <Name>Фунт-стерлинги Ингилистон</Name> 
   <Value>7,3156</Value> 
   </Valute>
...

and other

How can one get data from the Nominal and Value nodes by when Valute's attribute ID equals 826?

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Fara
  • 217
  • 2
  • 3
  • 9

1 Answers1

44

You can read XML simply by casting a string to [xml]:

$xml = [xml](Get-Content foo.xml)

Then you can use

$xml.ValCurs.Valute | Where-Object {$_.ID -eq 826} | Select-Object Nominal,Value

or shorter:

$xml.ValCurs.Valute | ? {$_.ID -eq 826} | select Nominal,Value
Joey
  • 344,408
  • 85
  • 689
  • 683