P
Peter Bailey
Hi,
I need to sort groups of xml data based on the first instances of
particular elements down deep in the element structure of documents.
regs = []
regs = XPath.match(doc, "//registration")
regs.each do |reg|
codes = XPath.match(regs, "//issue[1]/")# { |element| puts
element.text }
puts codes
end
I'm getting:
<issue code='ENG'>Energy/Nuclear</issue>
<issue code='EDU'>Education</issue>
<issue code='AGR'>Agriculture</issue>
...
There are only 86 entries of <issue> in the document, but, I'm getting
over 2,550 results here for "puts codes!" Obviously, it's looping and I
don't know why. It is pulling just the first entries, which I want, but,
obiously, it's doing it lots and lots of times.
I'm also trying to parse out these results, so that, I only end up with
the actual element text, not any attributes. So, for example, in the
above results, I only want "Energy/Nuclear, Education, and Agriculture,"
not any of the surrounding stuff. So, I've tried this, inside the above:
codes.each do |code|
code.to_s.gsub!(/<issue code='[A-Z]{3}'>(.*?)\/*.*<\/issue>/, "$1")
puts code
end
Thanks,
Peter
I need to sort groups of xml data based on the first instances of
particular elements down deep in the element structure of documents.
regs = []
regs = XPath.match(doc, "//registration")
regs.each do |reg|
codes = XPath.match(regs, "//issue[1]/")# { |element| puts
element.text }
puts codes
end
I'm getting:
<issue code='ENG'>Energy/Nuclear</issue>
<issue code='EDU'>Education</issue>
<issue code='AGR'>Agriculture</issue>
...
There are only 86 entries of <issue> in the document, but, I'm getting
over 2,550 results here for "puts codes!" Obviously, it's looping and I
don't know why. It is pulling just the first entries, which I want, but,
obiously, it's doing it lots and lots of times.
I'm also trying to parse out these results, so that, I only end up with
the actual element text, not any attributes. So, for example, in the
above results, I only want "Energy/Nuclear, Education, and Agriculture,"
not any of the surrounding stuff. So, I've tried this, inside the above:
codes.each do |code|
code.to_s.gsub!(/<issue code='[A-Z]{3}'>(.*?)\/*.*<\/issue>/, "$1")
puts code
end
Thanks,
Peter