# exampleb.rb -- translated to ruby from Paolo Casarini's exampleb.c # # Copyright (C) 2001 Paolo Casarini # Copyright (C) 2001 Tobias Peters # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this library; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. require "gdome" # /* First I get a DOMImplementation reference */ domimpl = Dom::implementation # /* I load a new document from the file name "exampleb.xml" */ doc = domimpl.createDocFromURI("exampleb.xml", Dom::LOAD_PARSING) # /* I get reference to the root element of the document */ root = doc.documentElement # /* I get the reference to the children NodeList of the root element */ children = root.childNodes # /* I add the attribute CHECKED="yes" to all element children of the root # element */ (0...children.length).each{ |i| el = children.item(i) if (el.kind_of?(Dom::Element)) el.setAttribute("CHECKED", "yes") end } # /* I save the modified document to a file named "exampleb_out.xml" */ domimpl.saveDocToFile(doc, "exampleb_out.xml", Dom::SAVE_STANDARD)