title: Find all nodes that have an attribute that matches a certain value with scala
body: <p>I saw the following example on <a href="http://www.nabble.com/Matching-XML-elements-with-a-specific-value-for-an-attribute-td23375285.html" rel="noreferrer">Nabble</a>, where the goal was to return all nodes that contain an attribute with an id of X that contains a value Y:</p>
  
  <pre><code>//find all nodes with an attribute "class" that contains the value "test"
  val xml = XML.loadString( """&lt;div&gt;
  &lt;span class="test"&gt;hello&lt;/span&gt;
  &lt;div class="test"&gt;&lt;p&gt;hello&lt;/p&gt;&lt;/div&gt;
  &lt;/div&gt;""" )
  
  def attributeEquals(name: String, value: String)(node: Node) = 
  { 
      node.attribute(name).filter(_==value).isDefined
  }
  
  val testResults = (xml \\ "_").filter(attributeEquals("class","test")) 
  //prints: ArrayBuffer(
  //&lt;span class="test"&gt;hello&lt;/span&gt;, 
  //&lt;div class="test"&gt;&lt;p&gt;hello&lt;/p&gt;&lt;/div&gt;
  //) 
  println("testResults: " + testResults ) 
  </code></pre>
  
  <p>As an extension to this how would one do the following: Find all nodes that contain any attribute that contains a value of Y:</p>
  
  <pre><code>//find all nodes with any attribute that contains the value "test"
  val xml = XML.loadString( """&lt;div&gt;
   &lt;span class="test"&gt;hello&lt;/span&gt;
   &lt;div id="test"&gt;&lt;p&gt;hello&lt;/p&gt;&lt;/div&gt;
   &lt;random any="test"/&gt;&lt;/div&gt;""" )
   //should return: ArrayBuffer(
   //&lt;span class="test"&gt;hello&lt;/span&gt;, 
   //&lt;div id="test"&gt;&lt;p&gt;hello&lt;/p&gt;&lt;/div&gt;, 
   //&lt;random any="test"/&gt; )
  </code></pre>
  
  <p>I was thinking I could use a _ like so:</p>
  
  <pre><code>val testResults = (xml \\ "_").filter(attributeEquals("_","test")) 
  </code></pre>
  
  <p>But it doesn't work. I know I can use pattern matching, but just wanted to see if I could do some magic with the filtering.</p>
  
  <p>Cheers - Ed</p>