I'm using Ruby 1.8.7 for a project.
I need to be able to parse and modify bits of XML code for it, and I'm running into a few problems. I am using Nokogiri to do the parsing.
I have the line:
<linking-phrase-appearance id="1JDLZ0609-JFP4ZP-TH" x="346" y="207" width="39" height="14"/>
I need to change it to:
<linking-phrase-appearance id="1JDLZ0609-JFP4ZP-TH" x="346" y="207" width="39" height="14" font-color="255 0 0 255"/>
I have code that finds the right lines to change, but when I change it nothing is written out to the output file.
This is the code I use to change the attribute:
# middle_node = id of line that needs to be changed (is unique to the line)
appearance = @xml.xpath("/xmlns:cmap/xmlns:map/xmlns:linking-phrase-appearance-list")
appearance.each do |node|
if node['id'] == middle_node
node['font-color'] = '255,0,0,255'
end
end
I assume there is some reason why this is not working but I'm unsure as to why.
node['<key>'] = '<value>'toonode.set_attribute('<key>', '<value>')seems to be working better but still havent got it to actually work outside of my irb console yet.