开发者

Ruby hpricot does not like dash in symbol, is there a workaround?

开发者 https://www.devze.com 2022-12-24 23:26 出处:网络
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

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:n开发者_如何学Goames: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


It should work, and it does work for me. A more detailed answer would require a more detailed error message than "Hpricot does not seem to like this".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号