Amrita 1.0.2 + XML + amrita_id fix

A

Aredridel

--=-ZacWyGgoCw44IiUQd5C9
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

For those still using Amrita 1.0.2 for whatever reason, I've made a
patch that makes setting amrita_id work when using REXML as a parser,
particularly so I can use amrita:id as my amrita_id.

The patch is attached.

Ari

--=-ZacWyGgoCw44IiUQd5C9
Content-Disposition: attachment; filename=amrita-xml-fubar.patch
Content-Type: text/x-patch; name=amrita-xml-fubar.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

diff -ur o-amrita-1.0.2/lib/amrita/xml.rb amrita-1.0.2/lib/amrita/xml.rb
--- o-amrita-1.0.2/lib/amrita/xml.rb 2005-04-01 00:58:59.718350000 -0700
+++ amrita-1.0.2/lib/amrita/xml.rb 2005-04-01 01:57:46.057114611 -0700
@@ -3,13 +3,16 @@
require "rexml/streamlistener"

module Amrita
+
has_uconv = true
+
begin
require 'uconv'
rescue LoadError
has_uconv = false
end
- if has_uconv
+
+ if has_uconv
case $KCODE
when "EUC"
def convert(s)
@@ -34,12 +37,12 @@
include Amrita
include REXML::StreamListener

-
- def initialize
+ def initialize(&block)
@stack = [ Null ]
+ @block = block
end

- def push(element)
+ def push(element)
@stack.unshift element
end

@@ -57,10 +60,11 @@
end

def tag_start(name, attrs)
- a = attrs.collect do |key, val|
+ a = attrs.collect { |key, val|
Attr.new(key, convert(val))
- end
- push e(name, *a)
+ }
+ t = @block.call(e(name, *a))
+ push t
push Null
end

@@ -83,23 +87,25 @@
end

def doctype(name, pub_sys, long_name, uri)
- s = SpecialElement.new('!',
- %Q[DOCTYPE #{name} #{pub_sys} #{long_name} #{uri}])
+ s = SpecialElement.new('!', %Q[DOCTYPE #{name} #{pub_sys} #{long_name} #{uri}])
push(pop + s)
end
end

module XMLParser
def XMLParser.parse_text(text, fname="", lno=0, dummy=nil, &block)
- l = Listener.new(&block)
+ l = Listener.new(&block)
REXML::Document.parse_stream(text, l)
l.result
end

def XMLParser.parse_file(fname, dummy=nil, &block)
- l = Listener.new(&block)
- REXML::Document.parse_stream(File.new(fname), l)
+ l = Listener.new(&block)
+ open(fname) { |fh|
+ REXML::Document.parse_stream(fh, l)
+ }
l.result
end
end
+
end

--=-ZacWyGgoCw44IiUQd5C9--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top