title: Using XPath to find all attributes in a particular namespace
body: <p>I'd like to see if any attributes exist in my XML document in a particular namespace. I thought that <code>//@ns:*</code> would do it, but this finds attributes any all namespaces:</p>
  
  <pre class="lang-ruby prettyprint-override"><code>require 'nokogiri' # Ruby library using libxml2
  doc = Nokogiri.XML '&lt;r xmlns:f="f" xmlns:b="b"&gt;&lt;e a="no" f:a="yes" b:a="no"/&gt;&lt;/r&gt;'
  p doc.xpath('//@f:*')
  #=&gt; [
  #=&gt;   #&lt;Nokogiri::XML::Attr:0x3fca52c02888 name="a" value="no"&gt;,
  #=&gt;   #&lt;Nokogiri::XML::Attr:0x3fca52c02874 name="a" namespace=#&lt;Nokogiri::XML::Namespace:0x3fca52c02450 prefix="f" href="foo"&gt; value="yes"&gt;,
  #=&gt;   #&lt;Nokogiri::XML::Attr:0x3fca52c02860 name="a" namespace=#&lt;Nokogiri::XML::Namespace:0x3fca52c08008 prefix="b" href="bar"&gt; value="no"&gt;
  #=&gt; ]
  </code></pre>
  
  <p>This same approach works when looking only for elements that match a namespace:</p>
  
  <pre class="lang-ruby prettyprint-override"><code>doc = Nokogiri.XML '&lt;r xmlns:f="foo" xmlns:b="bar"&gt;&lt;e/&gt;&lt;f:e/&gt;&lt;b:e/&gt;&lt;/r&gt;'
  p doc.xpath('//f:*')
  #=&gt; [
  #=&gt;   #&lt;Nokogiri::XML::Element:0x3fca524755ac name="e" namespace=#&lt;Nokogiri::XML::Namespace:0x3fca5247555c prefix="f" href="foo"&gt;&gt;
  #=&gt; ]
  </code></pre>
  
  <hr>
  
  <p>FWIW, the non-XPath workaround in Ruby is:</p>
  
  <pre class="lang-ruby prettyprint-override"><code>p doc.xpath('//@*').select{ |a| a.namespace &amp;&amp; a.namespace.prefix=='f' }
  #=&gt; [
  #=&gt;   #&lt;Nokogiri::XML::Attr:0x3fca52c02874 name="a" namespace=#&lt;Nokogiri::XML::Namespace:0x3fca52c02450 prefix="f" href="foo"&gt; value="yes"&gt;,
  #=&gt; ]
  </code></pre>