From: Phlip Date: 2005-09-24T13:26:40+09:00 Subject: Re: REXML Question mike leonard wrote: > I'm looking at REXML as a possible alternative to some things I've been > doing with XSLT, but I haven't the foggiest notion of how to accomplish > even the simplest transformations. Using REXML, how would I go about, > say, translating all 's into 's, or all 's into
type="chapter">'s? > > Thank you kindly in advance, REXML is a DOM-style parser, not a transformer. To do what you said, off the top of my head I would ... doc = Document.new(File.read('some.xml')) XPath.each(doc, '//em') do |node| node.name = 'emph' # or similar; check the members first end doc.write(File.open(''another.xml')) # or similar to write There; a transformation in a bottle. Because XPath.each() returns the actual DOM nodes inside the parsed tree, and because writing on these nodes changes that tree, you can loop thru the nodes and manipulate them using clever XPath expressions. The system will accomodate most of the XML rules for you. -- Phlip http://www.greencheese.org/ZeekLand <-- NOT a blog!!!