title: Getting the element name of an attribute in xml using powershell
body: <p>I would like to get the node name of an attribute using powershell. Can anyone please let me know if we have a built in function for the same.</p>
  
  <p>Following is my xml file called pricefile.xml</p>
  
  <pre><code> &lt;model type="model1" name="default" price="12.12" date="some_value"&gt;
    &lt;PriceData&gt;
      &lt;item name="watch" price="24.28" date="2013-12-01"/&gt;
      &lt;item name="toy" price="22.34" date="2013-12-02"/&gt;
      &lt;item name="bread" price="24.12" date="2013-12-03"/&gt;
    &lt;/PriceData&gt;
   &lt;/model&gt;
  </code></pre>
  
  <p>Say I want to get the element name "item" for the attribute "toy". How can I get this data?</p>
  
  <p>This is what I have so far.</p>
  
  <pre><code>[xml]$item = get-content pricefile.xml
  $item.SelectNodes("//item/@*")
  </code></pre>
  
  <p>which gives me the below output, but I do not know how to get the element of the attribute from here or it's parent node.</p>
  
  <pre><code>#text                                                                                                                                                  
  -----                                                                                                                                                  
  watch                                                                                                                                                  
  24.28                                                                                                                                                  
  2013-12-01                                                                                                                                             
  toy                                                                                                                                                    
  22.34                                                                                                                                                  
  2013-12-02                                                                                                                                             
  bread                                                                                                                                                  
  24.12                                                                                                                                                  
  2013-12-03 
  </code></pre>
  
  <p>If I use any of the below commands I get no output.</p>
  
  <pre><code>[xml]$item = get-content pricefile.xml
  
  $item.SelectNodes("//item/@*").parentnode
  
  $item.SelectNodes("//item/@*") | where {$_.parentnode}
  </code></pre>