title: Using XPath to select attributes with wildcards
body: <p>I got HTML I need to parse, and I'm using C# and Html Agility Pack Library to do the selection of nodes. My html will look something like either:   </p>
  
  <pre><code>&lt;input data-translate-atrr-placeholder="FORGOT_PASSWORD.FORM.EMAIL"&gt;
  </code></pre>
  
  <p>or : </p>
  
  <pre><code>&lt;h1 data-translate="FORGOT_PASSWORD.FORM.EMAIL"&gt;&lt;/h1&gt;
  </code></pre>
  
  <p>where <code>data-translate-attr-****</code> is the new pattern of attributes I need to find</p>
  
  <p>I could use something like this :</p>
  
  <pre><code>//[contains(@??,'data-translate-attr')]
  </code></pre>
  
  <p>but unfortunately, that will only search for value INSIDE an attribute. <strong>How do I look for the attribute itself, with a wildcard?</strong></p>
  
  <p><strong>Update :</strong> @Mathias Muller</p>
  
  <pre><code>HtmlAgilityPack.HtmlDocument htmlDoc    
  // this is the old code (returns nodes)
  var nodes = htmlDoc.DocumentNode.SelectNodes("//@data-translate");  
  // these suggestions return no nodes using the same data
  var nodes = htmlDoc.DocumentNode.SelectNodes("//@*[contains(name(),'data-translate')]");  
  var nodes = htmlDoc.DocumentNode.SelectNodes("//@*[starts-with(name(),'data-translate')]");
  </code></pre>
  
  <p><strong>Update 2</strong></p>
  
  <p>This appears to be an Html Agility Pack issue more than an XPath issue, I used chrome to test my XPath expressions and all of the following worked in chrome but not in Html Agility Pack :</p>
  
  <pre><code>//@*[contains(local-name(),'data-translate')]
  //@*[starts-with(name(),'data-translate')]
  //attribute::*[starts-with(local-name(.),'data-translate')]
  </code></pre>
  
  <p><strong>My Solution</strong> </p>
  
  <p>I ended up just doing things the old fashioned way...</p>
  
  <pre><code>var nodes = htmlDoc.DocumentNode.SelectNodes("//@*");
  
  if (nodes != null) {
      foreach (HtmlNode node in nodes) {
          if (node.HasAttributes) {
              foreach (HtmlAttribute attr in node.Attributes) {
                  if (attr.Name.StartsWith("data-translate")) {
                      // code in here to handle translation node
                  }
              }
          }
      }
  }
  </code></pre>