title: How to get XML node attribute values in Powershell?
body: <p>I have an XML file and I have to retrieve all its attributes. </p>
  
  <p>How to achieve that <em>without knowing their names and values?</em></p>
  
  <p>My XML file structure looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;TEST0&gt;
      &lt;TEST1&gt;
          &lt;TEST2&gt;
              &lt;TEST3 name="myname1" value="myvalue1" /&gt;
              &lt;TEST3 name="myname2" custVal="myvalue2" /&gt;
          &lt;/TEST2&gt;
      &lt;/TEST1&gt;
      &lt;TEST4&gt;
        &lt;TEST5 name="myname3" custVal="myvalue3"/&gt;
      &lt;/TEST4&gt;
  &lt;/TEST0&gt;
  </code></pre>
  
  <p>This is what I tried:</p>
  
  <pre><code> [System.Xml.XmlDocument] $xmlContent = new-object System.Xml.XmlDocument;
      $file = resolve-path('./myxml.xml');
      $xmlContent.load($file)
      $nodelist = $xmlContent.selectnodes("//*"); 
  
      foreach ($node in $nodelist) {
         Write-Host $node.Name " = " $node.Value
      }
  </code></pre>
  
  <p>This is the <strong>expected</strong> result:</p>
  
  <pre><code>myname1 = myvalue1
  myname2 = myvalue2
  myname3 = myvalue3
  </code></pre>
  
  <p>But this is <strong>my result</strong>:</p>
  
  <pre><code>myname1 = myvalue1
  myname2 = 
  myname3 = 
  </code></pre>
  
  <p><strong>THE PROBLEM:</strong> It searches for attribute named value, but not all my attributes are named like this, some of them are custom and I don't know the names. What can i do in this case?</p>
  
  <p><strong>UPDATE:</strong> To get the <em>actual</em> attributes names and values just add <strong>.Attribues</strong> in the loop:</p>
  
  <pre><code> foreach ($node in $nodelist) {
         Write-Host $node.Name " = " $node.Value
      }
  </code></pre>
  
  <p><strong>This returns:</strong></p>
  
  <pre><code>name = myname1 
  value = myvalue1
  name = myname2 
  custVal = myvalue2
  name = myname3 
  custVal = myvalue3
  </code></pre>