From: "Aleksi Niemelä" Date: 2000-12-11T16:34:24+09:00 Subject: [ruby-talk:7035] RE: XML-DOM Ruby implementation... Clemens Wyss asked: > is there (besides the SAX) a DOM implementaion available, which > allows adding/removing elements and writing the DOM-tree? Well, XMLParser http://www.ruby-lang.org/en/raa-list.rhtml?name=XMLParser does have a file xmltree.rb in it's lib directory. I strongly suspect you can use it's classes in a DOM way (I've never really used DOM, so can't say if this is fully compliant). Here's an example, inserting a xpointer after each element: - Aleksi require 'xmltreebuilder' def annotateWithXPointer(node, recursively = false) if recursively node.childNodes do |child| if child.type == XML::Element annotateWithXPointer(child, recursively) end end end xpointer = node.makeXPointer(false) annotate = XML::Element.new("xpointer", nil, [XML::Text.new(xpointer)]) node.insertBefore(annotate, node[0]) end builder = XML::SimpleTreeBuilder.new xml = STDIN.read begin tree = builder.parse(xml) rescue XMLParserError => xpe line = builder.line print "#{$0}: #{xpe} in line #{line}\n" exit 1 end root = tree.documentElement annotateWithXPointer(root, true) puts tree.to_s Given this input Ruby Mine opens Aleksi Niemela Aleksi.Niemela@ale.cx 2000-11-11 02:45

Just when the discussion sprouted on Ruby-talk I manage to finally open my site dedicated to Ruby and related biz and buzz.

Even though there has been no public announcement yet, the site is fully accessible. Everything is still heavily under construction, so don't be surprised if something doesn't work. Let me know, while we probably are already working on it.

it outputs root() <xpointer>root().child(1,title)</xpointer> Ruby Mine opens root().child(1,info) root().child(1,info).child(1,submitter) Aleksi Niemela root().child(1,info).child(1,email) Aleksi.Niemela@ale.cx root().child(1,info).child(1,datetime) 2000-11-11 02:45 root().child(1,body)

root().child(1,body).child(1,p) Just when the discussion sprouted on Ruby-talk I manage to finally open my site dedicated to Ruby and related biz and buzz.

root().child(1,body).child(2,p) Even though there has been no public announcement yet, the site is fully accessible. Everything is still heavily under construction, so don't be surprised if something doesn't work. Let me know, while we probably are already working on it.