2010-03-24 26 views
0

我想用hpricot解析一个xml文件。我想获得的XML元素有一个破折号,虽然因此,我面对的Ruby hpricot不喜欢符号中的破折号,有没有解决方法?

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| 
.......... 

这并不是由于仪表板的工作问题。如果我将标记重命名为transunit并相应地编辑符号引用,那么一切似乎都没有问题。我认为在引号之间使用符号应该可以工作,但hpricot似乎不喜欢这样。任何人都可以想到解决方法吗?

在此先感谢

回答

0

应该工作,并确实为我工作。更详细的答案需要比“Hpricot似乎不喜欢这个”更详细的错误信息。