title: How do I get a list of all of the XML tags in a file using PowerShell and Regular Expressions?
body: <p>This question is related to <a href="https://stackoverflow.com/questions/39329607/regex-find-all-xml-tags">RegEx find all XML tags</a> but I'm trying to do it in Windows PowerShell.  </p>
  
  <p>I have an XML file that contains many different XML tags, and the file is Huge, so basically I want to use RegEx to parse the file and spit out the name of all the tags as a list. The XML document is not a valid XML document even though it contains XML tags and elements. So using the XML functions of PowerShell won't work.  I get many errors when trying to view it as an XML document, thus the need to use RegEx.</p>
  
  <p>I've determined that the following RegEx identifies the tags (thanks to the related question mentioned above): <code>(?&lt;=&lt;)([^\/]*?)((?= \/&gt;)|(?=&gt;))</code></p>
  
  <p>Here's a very small sniplet of the file I'm parsing:</p>
  
  <pre><code>&lt;data&gt;&lt;bp_year /&gt;&lt;bp_make&gt;John Deere&lt;/bp_make&gt;&lt;bp_model&gt;650&lt;/bp_model&gt;&lt;bp_price&gt;3000.00&lt;/bp_price&gt;&lt;bp_txtDayPhone&gt;555-555-5555&lt;/bp_txtDayPhone&gt;&lt;bp_bestPrice&gt;3000.0000&lt;/bp_bestPrice&gt;&lt;bp_txtComments&gt;Best price available?&lt;/bp_txtComments&gt;&lt;bp_url&gt;https://www.example.com&lt;/bp_url&gt;&lt;/data&gt;
  &lt;data&gt;&lt;receiveOffers /&gt;&lt;link&gt;http://example.com/inventory.htm?id=2217405&amp;amp;used=1&lt;/link&gt;&lt;itemName&gt;2007 Yamaha RHINO 660&lt;/itemName&gt;&lt;/data&gt;
  &lt;data&gt;&lt;vehicleYear&gt;2008&lt;/vehicleYear&gt;&lt;vehicleMake&gt;Buick&lt;/vehicleMake&gt;&lt;vehicleModel&gt;Enclave&lt;/vehicleModel&gt;&lt;vehicleStyle&gt;CX&lt;/vehicleStyle&gt;&lt;vehicleInformation /&gt;&lt;vehicleMileage /&gt;&lt;phone&gt;555-555-5555&lt;/phone&gt;&lt;timeOfDay&gt;Morning&lt;/timeOfDay&gt;&lt;message /&gt;&lt;/data&gt;
  &lt;data&gt;&lt;mo_year&gt;2009&lt;/mo_year&gt;&lt;mo_make&gt;Webasto&lt;/mo_make&gt;&lt;mo_model&gt;Air Top 2000&lt;/mo_model&gt;&lt;mo_price /&gt;&lt;mo_txtDayPhone&gt;555-555-5555&lt;/mo_txtDayPhone&gt;&lt;mo_txtOffer&gt;700&lt;/mo_txtOffer&gt;&lt;mo_txtTrade /&gt;&lt;mo_txtComments /&gt;&lt;/data&gt;
  </code></pre>
  
  <p>I really don't have much experience with Powershell, but from my understanding, you can do Grep stuff with it.  After searching around on the internet, I found some resources that helped point me towards my solution, via using the powershell Select-String command.</p>
  
  <p>I've attempted the following powershell command, but it gives me way too much feedback.  I just want a master "Matches" list.</p>
  
  <pre><code>Select-String -Path '.\dataXML stuff - Copy.xml'-Pattern "(?&lt;=&lt;)([^\/]*?)((?= \/&gt;)|(?=&gt;))" -AllMatches | Format-List -Property Matches
  </code></pre>
  
  <p>Sample of Output generated:</p>
  
  <pre><code>Matches : {data, vehicleYear, vehicleMake, vehicleModel...}
  Matches : {data, address, city, region...}
  Matches : {data, vehicleYear, vehicleMake, vehicleModel...}
  Matches : {data, vehicleYear, vehicleMake, vehicleModel...}
  Matches : {data, address, city, region...}
  Matches : {data, vehicleYear, vehicleMake, vehicleModel...}
  Matches : {data, vehicleYear, vehicleMake, vehicleModel...}
  Matches : {data, mo_year, mo_make, mo_model...}
  </code></pre>
  
  <p>Basically, I want something like:</p>
  
  <pre><code>data
  vehicleYear
  vehicleMake
  vehicleModel
  address
  city
  region
  mo_year
  mo_make
  mo_model
  </code></pre>
  
  <p>and so on and on....</p>
  
  <p>Where only the matched strings are returned and listed, rather than telling me what matched on each line of the XML file. I prefer the list format because then I can pump this into Excel and get a distinct list of tag names, and then start actually doing what I need to accomplish, but the overwhelming number of different XML tags and not knowing what they are is holding me up.</p>
  
  <p>Maybe Select-String isn't the best method to use, but I feel like I'm close to my solution after finding this Microsoft post:
  <a href="https://social.technet.microsoft.com/Forums/windowsserver/en-US/d5bbd2fb-c8fa-43ed-b432-79ebfeee82ea/return-only-matches-from-selectstring?forum=winserverpowershell" rel="nofollow noreferrer">https://social.technet.microsoft.com/Forums/windowsserver/en-US/d5bbd2fb-c8fa-43ed-b432-79ebfeee82ea/return-only-matches-from-selectstring?forum=winserverpowershell</a></p>
  
  <p>Basically, here's the solution modified to fit my needs:</p>
  
  <pre><code>Gc 'C:\Documents\dataXML stuff - Copy.xml'|Select-String -Pattern "(?&lt;=&lt;)([^\/]*?)((?= \/&gt;)|(?=&gt;))"|foreach {$_.matches}|select value 
  </code></pre>
  
  <p>It provides a list of all the xml tags, just like I wanted, except it only returns the first XML tag of that line, so I get a lot of:</p>
  
  <pre><code>data
  data
  data
  </code></pre>
  
  <p>but no vehicleYear, vehicleMake, vehicleModel, etc., which would have been the 2nd or 3rd or 11th xml tag of that line.</p>