# How can i change the element in XML file?

**URL:** <https://www.ruby-forum.com/t/how-can-i-change-the-element-in-xml-file/119967>\
**Category:** Rails\
**Created:** [November 12, 2007, 4:26pm UTC](https://www.ruby-forum.com/t/how-can-i-change-the-element-in-xml-file/119967 "2007-11-12T16:26:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c4cdca/32.png) [@Baz](https://www.ruby-forum.com/u/Baz)\
**Post date:** [November 12, 2007, 4:26pm UTC](https://www.ruby-forum.com/t/how-can-i-change-the-element-in-xml-file/119967/1 "2007-11-12T16:26:56Z")

</div>

I am following the example in  
[http://www.xml.com/pub/a/2005/11/09/rexml-processing-xml-in-ruby.html?page=2](http://www.xml.com/pub/a/2005/11/09/rexml-processing-xml-in-ruby.html?page=2)

irb(main):001:0\> require ‘rexml/document’

irb(main):002:0\> include REXML

irb(main):003:0\> doc = Document.new(File.new(“bibliography.xml”))

irb(main):004:0\> root = doc.root

irb(main):005:0\> root.attributes[‘id’]

irb(main):006:0\> puts root.elements[1].elements[“author”]  
  
Godfrey  
Vesey

I can do “root.attributes[‘id’]=“XXX””…

irb(main):007:0\> puts root.attributes[‘id’]  
XXX  
=\> nil

Why cant i do  
root.elements[2].elements[“author”].elements[“firstname”]=“YYY”  
???

I would like to locate one of the elements and reassign the value. How  
can i do that?
