# How to modify a text value in a xml?

**URL:** <https://www.ruby-forum.com/t/how-to-modify-a-text-value-in-a-xml/181410>\
**Category:** Ruby\
**Created:** [January 11, 2010, 3:41pm UTC](https://www.ruby-forum.com/t/how-to-modify-a-text-value-in-a-xml/181410 "2010-01-11T15:41:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![milo\_luo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@milo\_luo](https://www.ruby-forum.com/u/milo_luo)\
**Post date:** [January 11, 2010, 3:41pm UTC](https://www.ruby-forum.com/t/how-to-modify-a-text-value-in-a-xml/181410/1 "2010-01-11T15:41:24Z")

</div>

Hi, folks  
I met a problem with xml. I can’t write to the file directly, here is my  
code:

f = File.open(FILE\_NAME)  
xml = REXML::Document.new(f)

xml.root.each\_element do |xml|  
xml.each\_element do |node|  
#if the node name equal to Properties  
if node.name == “Properties”  
node.each\_element do |child|  
#Get the child of Properties  
if child.name == “Name”  
#If the text equal to English, modified to the text to ABC  
if child.get\_text == “English”  
#What should I put here?  
child.text = “ABC”  
xml.write(f)  
end  
end  
end

```
end

```

end  
end

f.close

I want all the contents the same as the original file except the text of  
the node “Name”.  
How can I do that?

Thanks very much.

BR,  
Milo
