P
Peter Bailey
I've got an array, a listing of "titles" in an xml file. Basically, I
want to iterate through my file and, wherever I see the tag
<registration>, I want to replace that with <subhead.4>code</subhead.4>,
where "code" is the next entry in the stack of my array. Now, I've tried
this a number of ways and it does it, but, it doesn't cycle through my
array entries. It populates all of my substitutions with just the first
entry in the array, none of the subsequent ones.
...
$codes = []
$codes = xmlfile.scan(/<issueList>\s*<issue +code *="[A-Z]{3}
*">(.*?)<\/issue>\s*?/mi)
...
$codes.each do |code|
puts code
xmlfile.gsub!(/<registration>?/,
"<subhead.4>#{code}</subhead.4>/n<table>")
end
I'm getting the following. My "puts" statement, which is just there for
checking, does indeed list each entry of the array, though.
<subhead.4>Trade (Domestic & Foreign)</subhead.4>/n<table>
which is correct, but, I'm getting it for all 115 occurrences of the
<registration> tag.
Maybe gsub isn't the way to do this. Obviously, I'm trying to iterate
through every instance of <registration> and simply replace it with the
above code. Is gsub not an iteration tool?
Thanks a lot,
Peter
want to iterate through my file and, wherever I see the tag
<registration>, I want to replace that with <subhead.4>code</subhead.4>,
where "code" is the next entry in the stack of my array. Now, I've tried
this a number of ways and it does it, but, it doesn't cycle through my
array entries. It populates all of my substitutions with just the first
entry in the array, none of the subsequent ones.
...
$codes = []
$codes = xmlfile.scan(/<issueList>\s*<issue +code *="[A-Z]{3}
*">(.*?)<\/issue>\s*?/mi)
...
$codes.each do |code|
puts code
xmlfile.gsub!(/<registration>?/,
"<subhead.4>#{code}</subhead.4>/n<table>")
end
I'm getting the following. My "puts" statement, which is just there for
checking, does indeed list each entry of the array, though.
<subhead.4>Trade (Domestic & Foreign)</subhead.4>/n<table>
which is correct, but, I'm getting it for all 115 occurrences of the
<registration> tag.
Maybe gsub isn't the way to do this. Obviously, I'm trying to iterate
through every instance of <registration> and simply replace it with the
above code. Is gsub not an iteration tool?
Thanks a lot,
Peter