Ruby hpricot does not like dash in symbol, is there a workaround?
        Posted  
        
            by eakkas
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by eakkas
        
        
        
        Published on 2010-03-24T06:18:39Z
        Indexed on 
            2010/03/24
            6:23 UTC
        
        
        Read the original article
        Hit count: 365
        
ruby
|ruby-on-rails
I am trying to parse an xml file with hpricot. The xml element that I am trying to get has a dash though and hence the issue that I am facing
xml
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.1" version="1.1">
  <trans-unit>
    <source>"%0" can not be found. Please try again.</source>
    <target>"%0" can not be found. Please try again.</target>
  </trans-unit>
</xliff>
rb
  def read_in_xliff(xlf_file_name)
    stream = open(xlf_file_name) {|f| Hpricot(f)}
    (stream/:xliff/:'trans-unit').each do |transunit|
..........
This does not work because of the dash. If I rename the tag to transunit and edit the symbol reference accordingly everything seems to be fine. I thought using the symbol between quotes should work but hpricot does not seem to like this. Can anyone think of a workaround?
Thanks in advance
© Stack Overflow or respective owner