开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜