title: How to extract child nodes with the same child name but different values in PowerShell?
body: <p>Within the XML file, there are child nodes that have the same node name, but with different values as can be seen from the example.</p>
  
  <p>I have already tried what I could find on the internet, but alas, nothing worked. Moreover, I am new to PowerShell, and I've seen that it's really powerful, but this is just difficult because of a particular child node as you can see in the example.</p>
  
  <pre class="lang-bsh prettyprint-override"><code>chdir('\\folder')
  [xml]$XmlDocument = Get-Content "football.xml"
  </code></pre>
  
  <p>First try:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>foreach ($s in $XmlDocument.entities.entity.ext) {
      $attribs = $s.Attributes
      if ($attribs = 'Alias') {
          $s
      }
  }
  </code></pre>
  
  <p>Not sure what I am doing up here, but I was trying to loop through the file to get the value for the child node 'Alias' within the <code>&lt;ext&gt;</code> child node.</p>
  
  <p>Then I tried the following:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>$XmlDocument.SelectNodes("//entities/entity/ext") | ForEach Object {
      New-Object -Type PSObject -Property @{
          Name  = $s_.name
          Alias = $s_.alias
      }
  }
  </code></pre>
  
  <p>But this also didn't work. I also tried to export everything to CSV:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>$XmlDocument.entities.ChildNodes |
      Export-Csv "footballers.csv" -NoTypeInformation -Delimiter:";" -Encoding:UTF8
  </code></pre>
  
  <p>Which works really well, but the output for the <code>&lt;ext&gt;</code> child nodes is an aggregated error message.</p>
  
  <p>So the input would be like below. And as can be seen, the <code>&lt;ext&gt;</code> nodes are not equally distributed as well, which makes it even more difficult. Sometimes there are certain <code>&lt;ext&gt;</code> nodes in some entity and sometimes not.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;entities&gt;
      &lt;entity id="1" version="1928"&gt;
          &lt;name&gt;Ronaldo, Cristiano&lt;/name&gt;
          &lt;datebirth&gt;02/05/1985&lt;/datebirth&gt;
          &lt;country&gt;Portugal&lt;/country&gt;
          &lt;ext name="Alias"&gt;Ronnie&lt;/ext&gt;
          &lt;ext name="Height"&gt;187&lt;/ext&gt;
          &lt;ext name="Nationality"&gt;Portuguese&lt;/ext&gt;
          &lt;ext name="Club"&gt;Juventus&lt;/ext&gt;
          &lt;ext name="Previously"&gt;Real Madrid&lt;/ext&gt;
          &lt;ext name="Brand"&gt;CR7&lt;/ext&gt;
      &lt;/entity&gt;
      &lt;entity id="24" version="1928"&gt;
          &lt;name&gt;Messi, Lionel&lt;/name&gt;
          &lt;datebirth&gt;06/24/1987&lt;/datebirth&gt;
          &lt;country&gt;Argentina&lt;/country&gt;
          &lt;ext name="Alias"&gt;La Pulga&lt;/ext&gt;
          &lt;ext name="Height"&gt;170&lt;/ext&gt;
          &lt;ext name="Nationality"&gt;Argentine&lt;/ext&gt;
          &lt;ext name="Club"&gt;FC Barcelona&lt;/ext&gt;
      &lt;/entity&gt;
  &lt;/entities&gt;
  </code></pre>
  
  <p>And then I would like to convert all of this into a CSV file with all information inside the output.</p>