REXML & Root Node

Hi:

I’m getting errors from REXML with leading whitespace when I have an XML
Declaration - see below. (Problem doesn’t show up when I omit the
Declaration.) Any ideas?

Also I’m not quite sure why the document element is returned by the root
method. Surely the root node is the outermost container which wraps document
element, PI’s, XML Declaration, whitespace, etc.?

Thanks for any insights,
Tony

% cat test-rexml
#!/usr/local/bin/ruby

require ‘rexml/document’; include REXML

doc = Document.new File.new(‘tmp.xml’)

% test-rexml
/usr/local/lib/ruby/site_ruby/1.6/rexml/document.rb:234:in `parse’:
attempted a
ding second root element to document (REXML::ParseException)

% cat tmp.xml

<?xml version="1.0" encoding="UTF-8"?>

% test-rexml
/usr/local/lib/ruby/site_ruby/1.6/rexml/element.rb:686:in `base_parser’:
malfor
ed XML: missing tag start (REXML::ParseException)

% cat tmp.xml

<?xml version="1.0" encoding="UTF-8"?>

I’m getting errors from REXML with leading whitespace when I have an XML
Declaration - see below. (Problem doesn’t show up when I omit the
Declaration.) Any ideas?

Could you be a little more precise about what you mean by ‘leading
whitespace’? If it’s whitespace before the XML declaration, you should
be getting an error … although I don’t get an error either with or
without the whitespace. What version of REXML are you using (I’m using
2.5.1)?

Also I’m not quite sure why the document element is returned by the root
method. Surely the root node is the outermost container which wraps document
element, PI’s, XML Declaration, whitespace, etc.?

Sure … but the root method returns the root element, which is
another name for the document element. I guess whether that’s intuitive
or not is in the eye of the beholder (it is for me), but since, for all
practical purposes, the root node is equivalent to the document
object, why would you need a method to get it anyway?

···

On Tue, Oct 08, 2002 at 01:38:05AM +0900, Hammond, Tony (ELSLON) wrote:


Matt Gushee
Englewood, Colorado, USA
mgushee@havenrock.com