REXML article on XML.com

There a nice article by Koen Vervloesem about REXML up on the XML.com site:

http://www.xml.com/pub/a/2005/11/09/rexml-processing-xml-in-ruby.html?CMP=OTC-TY3388567169

James Britt

···

--

http://www.ruby-doc.org - Ruby Help & Documentation
http://www.artima.com/rubycs/ - Ruby Code & Style: Writers wanted
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
http://www.30secondrule.com - Building Better Tools

I'm afraid it's not proper reporting here.

$ ruby code1.rb
/usr/lib/ruby/site_ruby/rexml/document.rb:187:in `build': undefined
method `add_element' for nil:NilClass (NoMethodError)
        from /usr/lib/ruby/site_ruby/rexml/document.rb:44:in `initialize'
        from code1.rb:4:in `new'
        from code1.rb:4

$ ruby code2.rb
/usr/lib/ruby/site_ruby/rexml/document.rb:187:in `build': undefined
method `add_element' for nil:NilClass (NoMethodError)
        from /usr/lib/ruby/site_ruby/rexml/document.rb:44:in `initialize'
        from code2.rb:21:in `new'
        from code2.rb:21

However, code3.rb worked well.

···

On 11/14/05, James Britt <james_b@neurogami.com> wrote:

There a nice article by Koen Vervloesem about REXML up on the XML.com site:

REXML: Processing XML in Ruby

James Britt

--

http://www.ruby-doc.org - Ruby Help & Documentation
Ruby Code & Style - Ruby Code & Style: Writers wanted
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
http://www.30secondrule.com - Building Better Tools

--
http://nohmad.sub-port.net

James Britt wrote:

There a nice article by Koen Vervloesem about REXML up on the XML.com site:

REXML: Processing XML in Ruby

The heredoc input string and two example files
(bibliography.xml and bibliography2.xml) contain:

   <?xml version="1.0" encoding="ISO-8859-15"?>

causing REXML to barf. Changing to ISO-8859-1
(or removing) fixes. ISO-8859-15 is unsupported.

I should email Koen but maybe you're in contact, James :-?

daz

REXML could not parse DTD.
I could not even run examples including DTD from REXML tutorial page.[1]

Any thought?

[1]: http://www.germane-software.com/software/rexml/docs/tutorial.html

···

On 11/15/05, Gyoung-Yoon Noh <nohmad@gmail.com> wrote:

On 11/14/05, James Britt <james_b@neurogami.com> wrote:
> There a nice article by Koen Vervloesem about REXML up on the XML.com site:
>
> REXML: Processing XML in Ruby
>
> James Britt
>
>
> --
>
> http://www.ruby-doc.org - Ruby Help & Documentation
> Ruby Code & Style - Ruby Code & Style: Writers wanted
> http://www.rubystuff.com - The Ruby Store for Ruby Stuff
> http://www.jamesbritt.com - Playing with Better Toys
> http://www.30secondrule.com - Building Better Tools
>
>

I'm afraid it's not proper reporting here.

$ ruby code1.rb
/usr/lib/ruby/site_ruby/rexml/document.rb:187:in `build': undefined
method `add_element' for nil:NilClass (NoMethodError)
        from /usr/lib/ruby/site_ruby/rexml/document.rb:44:in `initialize'
        from code1.rb:4:in `new'
        from code1.rb:4

$ ruby code2.rb
/usr/lib/ruby/site_ruby/rexml/document.rb:187:in `build': undefined
method `add_element' for nil:NilClass (NoMethodError)
        from /usr/lib/ruby/site_ruby/rexml/document.rb:44:in `initialize'
        from code2.rb:21:in `new'
        from code2.rb:21

However, code3.rb worked well.

--
http://nohmad.sub-port.net

--
http://nohmad.sub-port.net

daz wrote:
...

The heredoc input string and two example files
(bibliography.xml and bibliography2.xml) contain:

   <?xml version="1.0" encoding="ISO-8859-15"?>

causing REXML to barf. Changing to ISO-8859-1
(or removing) fixes. ISO-8859-15 is unsupported.

I should email Koen but maybe you're in contact, James :-?

No. I just happened to hear about the article and thought it worth a mention here. I skimmed it, but did not read through it, and have no contact with the author.

But I posted a quick comment on the site.

James

···

--

http://www.ruby-doc.org - Ruby Help & Documentation
Ruby Code & Style - Ruby Code & Style: Writers wanted
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
http://www.30secondrule.com - Building Better Tools

Thanks for testing and finding the bug! I'm not involved with the project but
did find this on the author's website:

"You can submit bug reports and feature requests, and view the list of known
bugs, at the REXML bug report page. Please do submit bug reports. If you really
want your bug fixed fast, include an runit or Test::Unit method (or methods)
that illustrates the problem. At the very least, send me some XML that REXML
doesn't process properly.

You don't have to send an entire test suite -- just the unit test methods. If
you don't send me a unit test, I'll have to write one myself, which will mean
that your bug will take longer to fix.

When submitting bug reports, please include the version of Ruby and of REXML
that you're using, and the operating system you're running on. Just run: ruby
-vrrexml/rexml -e 'p REXML::Version,PLATFORM' and paste the results in your bug
report."

James Britt wrote:

But I posted a quick comment on the site.

Splendid idea! One of those interactive doo-dahs.
Wish I'd written in English, now.
Barf must be a word I picked up here :slight_smile:

Thanks,

daz

Kevin Bedell wrote:

Thanks for testing and finding the bug!

It's not a REXML bug - it's an unsupported encoding.

Thanks, any way.

daz

daz wrote:

Kevin Bedell wrote:

Thanks for testing and finding the bug!

It's not a REXML bug - it's an unsupported encoding.

Thanks, any way.

daz

Unsupported? But there's

/ruby/lib/ruby/1.8/rexml/encodings/ISO-8859-15.rb

in my Ruby installation (One-Click-Installer 1.8.2-15 Stable Release).

And over here XML starting with

<?xml version="1.0" encoding="ISO-8859-15"?>

gets read without any hassle. Did I miss something?

Happy rubying

Stephan

Stephan Kämper wrote:

daz wrote:
>
> It's not a REXML bug - it's an unsupported encoding.
>

Unsupported?

Sorry, I was misled by the tutorial page:

"... other encodings (UTF-8, UTF-16, ISO-8859-1, and UNILE
  are all supported, input and output) ..."

But there's
/ruby/lib/ruby/1.8/rexml/encodings/ISO-8859-15.rb
in my Ruby installation (One-Click-Installer 1.8.2-15 Stable Release).

I have that file on that path and I used 1.8.2-15 also.

And over here XML starting with
<?xml version="1.0" encoding="ISO-8859-15"?>
gets read without any hassle. Did I miss something?

Now you say so, I think I should get that, too.

p $:.any? {|d| File.exist?(File.join(d, 'rexml/encodings/ISO-8859-15.rb'))}
#-> true

require 'rexml/document'
p REXML::Version
puts 'ruby %s (%s) [%s]' % [RUBY_VERSION, RUBY_RELEASE_DATE, RUBY_PLATFORM]

string = '<?xml version="1.0" encoding="ISO-8859-1"?>'
doc = REXML::Document.new(string)
puts doc
puts '~'*40
string = '<?xml version="1.0" encoding="ISO-8859-15"?>'
doc = REXML::Document.new(string)
puts doc

=begin

"3.1.2.1"
ruby 1.8.2 (2004-12-25) [i386-mswin32]
<?xml version='1.0' encoding='ISO-8859-1'?>

···

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:/RUBY/lib/ruby/1.8/rexml/output.rb:17:
in `<<': undefined method `encode' for #<REXML::Output:0x4ed44f4> (NoMethodError)
    from D:/RUBY/lib/ruby/1.8/rexml/xmldecl.rb:43:in `write'
    from D:/RUBY/lib/ruby/1.8/rexml/document.rb:163:in `write'
    from D:/RUBY/lib/ruby/1.8/rexml/document.rb:161:in `each'
    from D:/RUBY/lib/ruby/1.8/rexml/document.rb:161:in `write'
    from D:/RUBY/lib/ruby/1.8/rexml/node.rb:23:in `to_s'
    from D:/ruby/DfB/ReXML/rbA163.TMP:14:in `puts'
    from D:/ruby/DfB/ReXML/rbA163.TMP:14

=end

daz

daz wrote:

And over here XML starting with
<?xml version="1.0" encoding="ISO-8859-15"?>
gets read without any hassle. Did I miss something?

Now you say so, I think I should get that, too.

p $:.any? {|d| File.exist?(File.join(d, 'rexml/encodings/ISO-8859-15.rb'))}
#-> true

require 'rexml/document'
p REXML::Version
puts 'ruby %s (%s) [%s]' % [RUBY_VERSION, RUBY_RELEASE_DATE, RUBY_PLATFORM]

string = '<?xml version="1.0" encoding="ISO-8859-1"?>'
doc = REXML::Document.new(string)
puts doc
puts '~'*40
string = '<?xml version="1.0" encoding="ISO-8859-15"?>'
doc = REXML::Document.new(string)
puts doc

=begin

"3.1.2.1"
ruby 1.8.2 (2004-12-25) [i386-mswin32]
<?xml version='1.0' encoding='ISO-8859-1'?>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:/RUBY/lib/ruby/1.8/rexml/output.rb:17:
in `<<': undefined method `encode' for #<REXML::Output:0x4ed44f4> (NoMethodError)
    from D:/RUBY/lib/ruby/1.8/rexml/xmldecl.rb:43:in `write'
    from D:/RUBY/lib/ruby/1.8/rexml/document.rb:163:in `write'
    from D:/RUBY/lib/ruby/1.8/rexml/document.rb:161:in `each'
    from D:/RUBY/lib/ruby/1.8/rexml/document.rb:161:in `write'
    from D:/RUBY/lib/ruby/1.8/rexml/node.rb:23:in `to_s'
    from D:/ruby/DfB/ReXML/rbA163.TMP:14:in `puts'
    from D:/ruby/DfB/ReXML/rbA163.TMP:14

=end

daz

Hmm, now that you mention it... I have that problem with writing XML with

     encoding="ISO-8859-15"

too. But then I can output XML using this:

require 'rexml/document'

# REXML::Attribute.class_eval( %q^
# def to_string
# %Q[#@expanded_name="#{to_s().gsub(/"/, '&quot;')}"]
# end
# ^ )

fn = 'sample.xml'
doc = REXML::Document.new( File.open( fn ) )

puts doc.xml_decl.to_s
puts doc.root

sample.xml is:

<?xml version="1.0" encoding="ISO-8859-15"?>
<Widget a_tribute='this is OK' and_so="is this" />

This example is the 'essence' of my single/double quoting issue of attributes, of course. Commenting in the 5 lines above will lead to doubly quoted attribute values.

Happy rubying

Stephan