Answer the question
In order to leave comments, you need to log in
How to remove tags in xml using Ruby?
I processed the xml file. Now its contents are in the doc variable. I want to create a loop that will edit each line, removing the "" tag from there. Help me please.
if (Gem.win_platform?)
Encoding.default_external = Encoding.find(Encoding.locale_charmap)
Encoding.default_internal = __ENCODING__
[STDIN, STDOUT].each do |io|
io.set_encoding(Encoding.default_external, Encoding.default_internal)
end
end
require "rexml/document"
require "date"
file_xml = File.open("file.xml", encoding: "utf-8")
doc = REXML::Document.new(file_xml)
doc.elements.each("page/item") do |element|
#
end
<item found="1124120">bmw x5</item>
<item found="967578">audi q7</item>
<item found="127888">lada vesta</item>
Answer the question
In order to leave comments, you need to log in
doc.elements.each("page/item") do |element|
element.delete_attribute("found")
doc.delete_element "/page/item"
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question