开发者

Nokogiri found only one element instead of three

#src
<ExpenseType name="Verpfl24" calcQty="24"  showTip="0"  tipText=""  selfTax="0"  showForeign="0"  description="Verpflegungsmehraufwand 24 Stunden" />
<ExpenseType name="Verpfl14" calcQty="14"  showTip="0"  tipText=""  selfTax="0"  showForeign="0"  description="Verpflegungsmehraufwand 14 Stunden" />
<ExpenseType name="Verpfl8" calcQty="8"  showTip="0"  tipText=""  selfTax="0"  showForeign="0"  description="Verpflegungsmehraufwand 8 Stunden" />

doc = Nokogiri::XML(src)
items = doc.search("/ExpenseType")
items.size # 1 instead of 3

I have made some investigation and found:

doc.document.to_s 

"<?xml version="1.0"?>\n<ExpenseType name="Verpfl24" calcQty="24" showTip="0" tipText="" selfTax="0" showForeign="0" description="Verpflegungsmehraufwand 24 Stunden"/>\n"

What I'm doing wrong ?

I want simp开发者_StackOverflow中文版ly all ExpenseType elements from this xml


An xml document (unlike an xml fragment) can only contain exactly one top-level element. Put some <wrapper> element around your input string and you should be able to find all three expense types.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜