title: powershell script - obtain an attribute value using xmlPath where multiple attribute filters are used
body: <p>I have multiple XML files I have to extract data from and prepare a CSV file of certain data.</p>
  <p>I need to find an attribute value where an element contains multiple attributes and I need to filter on the attributes too.</p>
  <p>In the below example, how do I get the value of &quot;123456AB&quot; in an AuthID csv field please? I've tried more than just the 5 examples below with no success.</p>
  <p>Note, the xml &amp; code have been simplified (code/structure/values) as I can't post the whole example.</p>
  <p>Thanks</p>
  <p>XML excerpt:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; standalone=&quot;yes&quot;?&gt;
  &lt;?xml-stylesheet href=&quot;somestylesheet.xsl&quot; type=&quot;text/xsl&quot;?&gt;
  &lt;MyDocument xmlns:ext=&quot;namespace1&quot; xmlns:xsi=&quot;namespace2&quot; xmlns=&quot;defaultnamespace&quot;&gt;
    &lt;ext:asEntityIdentifier classCode=&quot;IDENT&quot;&gt;
      &lt;ext:id root=&quot;123.456.0.12341&quot; assigningAuthorityName=&quot;ABC-1&quot; /&gt;
    &lt;/ext:asEntityIdentifier&gt;
    &lt;ext:asEntityIdentifier classCode=&quot;IDENT&quot;&gt;
      &lt;ext:id root=&quot;1656.123.2&quot; extension=&quot;123456AB&quot; assigningAuthorityName=&quot;Some Auth Name&quot; /&gt;
    &lt;/ext:asEntityIdentifier&gt;
  &lt;/MyDocument&gt;
  </code></pre>
  <p>Powershell script excerpt</p>
  <pre><code># Read in the xml file content
  [xml]$xmlData = Get-Content -Path &quot;C:\temp\mytest.xml&quot;
  
  # Declare the multiple XML Namespaces required
  $nsMngr = New-Object System.Xml.XmlNameSpaceManager($xmlData.NameTable)
  $nsMngr.AddNamespace(&quot;ns&quot;, $xmlData.DocumentElement.NamespaceURI)   # default
  $nsMngr.AddNamespace(&quot;ext&quot;, &quot;namespace1&quot;)
  
  # Prepare a PSCustomObject of the relevant xml data
  $reqdData = [PSCustomObject]@{
  
      AuthID1 $xmlData.SelectSingleNode(&quot;//ns:MyDocument/ext:asEntityIdentifier[@classCode=&quot;&quot;IDENT&quot;&quot;]/ext:id[@assigningAuthorityName=&quot;&quot;Some Auth Name&quot;&quot;]&quot;, $nsMngr)
  
      AuthID2 $xmlData.SelectSingleNode(&quot;//ns:MyDocument/ext:asEntityIdentifier[@classCode=&quot;&quot;IDENT&quot;&quot;]/ext:id[@assigningAuthorityName=&quot;&quot;Some Auth Name&quot;&quot;]&quot;, $nsMngr) | select extension
  
      AuthID3 $xmlData.SelectSingleNode(&quot;//ns:MyDocument/ext:asEntityIdentifier[@classCode=&quot;&quot;IDENT&quot;&quot;]/ext:id[@assigningAuthorityName=&quot;&quot;Some Auth Name&quot;&quot;]/extension&quot;, $nsMngr)
      
      AuthID4 $xmlData.SelectSingleNode(&quot;//ns:MyDocument/ext:asEntityIdentifier[@classCode=&quot;&quot;IDENT&quot;&quot;]/ext:id[@assigningAuthorityName=&quot;&quot;Some Auth Name&quot;&quot;]/ext:extension&quot;, $nsMngr)
  
      AuthID5 $xmlData.SelectSingleNode(&quot;//ns:MyDocument/ext:asEntityIdentifier[@classCode=&quot;&quot;IDENT&quot;&quot;]/ext:id[@assigningAuthorityName=&quot;&quot;Some Auth Name&quot;&quot;]/@extension&quot;, $nsMngr)
  
  }
  
  # Write the relevant data to a csv file
  $reqdData | Export-Csv -Path $extractFile -NoTypeInformation -Force -Append
  
  # CSV content: AuthID1 = &quot;System.Xml.XmlElement&quot;, AuthID2 = &quot;@{extension=123456AB}&quot;, AuthID3 and 4 both blank, AuthID5 = &quot;System.Xml.XmlAttribute&quot;
  </code></pre>