Changeset 166

Show
Ignore:
Timestamp:
08/26/2008 21:06:37 (3 months ago)
Author:
alexpooley
Message:

Fixed xpath search when getting attribute value

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/hpricot/traverse.rb

    r161 r166  
    285285              nodes = [self] 
    286286          else 
    287               m = expr.match(%r!^([#.]?)([a-z0-9\\*_-]*)!i).to_a 
     287              m = expr.match(%r!^([#\@.]?)([a-z0-9\\*_-]*)!i).to_a 
    288288              after = $' 
    289289              mt = after[%r!:[a-z0-9\\*_-]+!i, 0] 
     
    297297                  oid = get_element_by_id(m[2]) 
    298298                  nodes = oid ? [oid] : [] 
     299                  expr = after 
     300              elsif m[1] == '@' 
     301                  ret = [] 
     302                  nodes.each do |node| 
     303                      ret << node.parent.get_attribute(m[2]) 
     304                  end 
     305                  nodes = ret 
    299306                  expr = after 
    300307              else 
  • trunk/test/test_parser.rb

    r161 r166  
    7474    assert_equal 'link1', (doc/:p/:a).first['id'] 
    7575    assert_equal 'link1', doc.search('p').at('a').get_attribute('id') 
     76    assert_equal 'link1', doc.at("//a/@id") 
    7677    assert_equal 'link2', (doc/'p').filter('.ohmy').search('a').first.get_attribute('id') 
    7778    assert_equal (doc/'p')[2], (doc/'p').filter(':nth(2)')[0]