From: Sean Russell Date: 2001-10-13T04:41:30+09:00 Subject: [ruby-talk:22476] Re: REXML Tobias Reif wrote: > the following works with NQXML. > > How to write the equivalent for REXML? Hiho. I hope you've by now found the (new) Tutorial and links to the API documentation. If you would still like clarification, please let me know. By the way, lately I've been hacking on REXML a lot, adding functionality especially to XPath, and squashing bugs as they are reported. In any case, I sometimes update REXML a couple of times a day; I've stopped updating the RAA site everytime I do so, because some people may find it annoying. As a result, I'll just post minor release announcements to this newsgroup, and I'll save the RAA updates for every couple of days. As I said, I've made a number of changes to REXML recently; two are fairly significant. The first relates to a bug in DocType processing that was breaking REXML document processing in some cases. The second is that I've expanded and debugged XPath support considerably. The only thing missing now is axes:: and function() support, and I'm currently in the process of adding axes:: support. Also, I've rethought my decision to make XPath processing part of the Elements class, and have extracted it out into its own class. This doesn't change how you use Element.elements[...] (or any other XPath methods), but it does allow you another access point for XPath and it makes it easier for me to maintain. The current version is 0.9.4, and is available at the usual place. Ah, what the heck. Here's your translation... I tried to make it as identical to your original code. ############### TRANSLATION copy require 'rexml/document' main_doc = open('main_doc.xml') do |file| file.read end news_template = open('news_template.xml') do |file| file.read end content_repository = open('content_repository.xml') do |file| file.read end main_doc_tree = REXML::Document.new main_doc news_template_tree = REXML::Document.new news_template content_repository_tree = REXML::Document.new content_repository content_repository_to_include = content_repository_tree.root.children[5] # Why this and not children[3]? news_template_to_include = news_template_tree.root.children[0].next_sibling.next_sibling.next_sibling news_template_to_include << content_repository_to_include main_doc_tree.root << news_template_to_include out = '' main_doc_tree.write out puts out ############### TRANSLATION END ############### TRANSLATION Sean's way require 'rexml/document' main_doc_tree = open('main_doc.xml'){|f| REXML::Document.new f} news_template_tree = open('news_template.xml){|f| REXML::Document.new f} content_repository_tree = open('content_repository.xml') {|f| REXML::Document.new f } news_template_to_include = news_template_tree.root.children[3] news_template_to_include << content_repository_tree.root.children[5] main_doc_tree.root << news_template_to_include puts main_doc_tree ############### TRANSLATION END --- SER