【发布时间】:2014-03-17 01:33:31
【问题描述】:
我在 Ruby 中使用 Nokogiri 编写了一个 SAX 解析器,并且我正在解析一个非常大的 xml 文件。 奇怪的是,使用
data.each do |node|
if (node.name == "product" && node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT)
#puts p.inspect
p = Nokogiri::XML.parse(node.outer_xml)
#puts p.xpath("//xmlns:step-quantity").text
images = []
sizes = []
colors = []
# If product is a master
if p.xpath('//xmlns:image-group[@view-type="re_detail"]/xmlns:image/@path').count != 0
# Product ID
product_id = p.xpath('//@product-id').text # <--- THIS
返回
hbeu5010140440462983591054046298359112404629835912940462983591364046298359143404629835915040462983591674046298359174
对于 XML
<product product-id="hbeu50101404">
<ean/>
<upc/>
<unit/>
<min-order-quantity>1</min-order-quantity>
<step-quantity>1</step-quantity>
我不明白为什么? 我会缩短字符串长度,但有些 ID 更长,我觉得那种脏。 有人可以帮我吗? :-)
提前致谢
本杰明
【问题讨论】: