Is REXML included in the InstantRails 1.3 build? Does it work via irb? I''m trying to work through the tutorial at http://www.germane-software.com/software/rexml/docs/tutorial.html and thought I''d try irb at the same time. But right off, I run into the ''unitialized constant Document'' error shown below. Any ideas? Thanks, Bill -------------- irb input/output -------------- C:\InstantRails-1.3\rails_apps\sandbox>irb irb(main):001:0> require "rexml/document" => true irb(main):002:0> file=File.new("public/mydoc.xml") => #<File:public/mydoc.xml> irb(main):003:0> doc=Document.new file NameError: uninitialized constant Document from (irb):3 irb(main):004:0> -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/instantrails-users/attachments/20060428/dedc70f8/attachment-0001.htm
On 4/28/06, Bill Walton <bill.walton at charter.net> wrote:> > Is REXML included in the InstantRails 1.3 build? Does it work via irb? > I''m trying to work through the tutorial at > http://www.germane-software.com/software/rexml/docs/tutorial.html and > thought I''d try irb at the same time. But right off, I run into the > ''unitialized constant Document'' error shown below. Any ideas? > > Thanks, > Bill > > -------------- irb input/output -------------- > C:\InstantRails-1.3\rails_apps\sandbox>irb > irb(main):001:0> require "rexml/document" > => true > irb(main):002:0> file=File.new("public/mydoc.xml") > => #<File:public/mydoc.xml> > irb(main):003:0> doc=Document.new file > NameError: uninitialized constant Document > from (irb):3 > irb(main):004:0> >REXML is inlcuded in Ruby. I just looked at REXML''s document.rb file (in lib\ruby\1.8\xml) and the Document class is defined inside of a module named REXML. So you need to do this: doc = REXML::Document.new Curt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/instantrails-users/attachments/20060428/ecd7de9d/attachment.htm
On 4/29/06, Curt Hibbs <curt.hibbs at gmail.com> wrote:> > REXML is inlcuded in Ruby. I just looked at REXML''s document.rb file (in > lib\ruby\1.8\xml) and the Document class is defined inside of a module named > REXML. So you need to do this: > > doc = REXML::Document.newOr include REXML doc = Document.new I don''t know if that''s a good solution in this case, but it''s another thing you can try! Gavin
Hi Curt, Gavin; Thanks for your replies. I''ve tried both suggestions and, unfortunately, it still gives me errors. I''d really appreciate it if you''d take a look at the irb input / output below and tell me if you can tell what I''m doing wrong. Thanks! --------------- irb session --------------- C:\InstantRails-1.3\rails_apps\sandbox>irb irb(main):001:0> require "rexml/document" => true irb(main):002:0> file=File.new("public/mydoc.xml") => #<File:public/mydoc.xml> irb(main):003:0> doc=REXML::Document.new file => <UNDEFINED> ... </> [BW] I assume the <UNDEFINED> error message above is referring to Document. One thing I don''t understand though is why the ''require'' on the first line of input is successful since rexml/document.rb is over in another branch of the directory tree. For now, I''m just assuming irb knows where to find what it needs. It returns true, so I figure it found it. But if irb found document.rb, then why is the ''doc='' line failing? [BW] So I figured I''d give Gavin''s approach a shot. irb(main):004:0> include REXML => Object irb(main):005:0> doc = Document.new file NoMethodError: undefined method `[]'' for nil:NilClass from C:/InstantRails-1.3/ruby/lib/ruby/1.8/rexml/source.rb:131:in `initialize'' from C:/InstantRails-1.3/ruby/lib/ruby/1.8/rexml/parsers/baseparser.rb:126:in `stream='' from C:/InstantRails-1.3/ruby/lib/ruby/1.8/rexml/parsers/baseparser.rb:100:in `initialize'' from C:/InstantRails-1.3/ruby/lib/ruby/1.8/rexml/parsers/treeparser.rb:8:in `initialize'' from C:/InstantRails-1.3/ruby/lib/ruby/1.8/rexml/document.rb:178:in `build'' from C:/InstantRails-1.3/ruby/lib/ruby/1.8/rexml/document.rb:45:in `initialize'' from (irb):5 [BW] Hmmm.... That didn''t see to make things better ;-( So I tried it without passing in the file argument. irb(main):006:0> doc=Document.new => <UNDEFINED/> [BW] So it definitely looks to me like it''s the Document.new that''s throwing the error. Any ideas? I sure would appreciate it if you''d try entering these commands on your systems and letting me know if you get any different results. Maybe there''s something wrong with my config. I''ve included the content of "mydoc.xml" below. I put it in the ''public'' directory. Thanks, Bill ------------------ mydoc.xml --------------------- <inventory title="OmniCorp Store #45x10^3"> <section name="health"> <item upc="123456789" stock="12"> <name>Invisibility Cream</name> <price>14.50</price> <description>Makes you invisible</description> </item> <item upc="445322344" stock="18"> <name>Levitation Salve</name> <price>23.99</price> <description>Levitate yourself for up to 3 hours per application</description> </item> </section> <section name="food"> <item upc="485672034" stock="653"> <name>Blork and Freen Instameal</name> <price>4.95</price> <description>A tasty meal in a tablet; just add water</description> </item> <item upc="132957764" stock="44"> <name>Grob winglets</name> <price>3.56</price> <description>Tender winglets of Grob. Just add water</description> </item> </section> </inventory> -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/instantrails-users/attachments/20060429/98863db0/attachment.htm
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Bill Walton wrote:> irb(main):003:0> doc=REXML::Document.new file > => <UNDEFINED> ... </> > [BW] I assume the <UNDEFINED> error message above is referring to > Document. One thing I don''t understand though is why the ''require'' onI don''t think that''s an error, I think <UNDEFINED> is part of the XML object. Irb tries to output some descriptive text about the object. So this is normal. Indeed, I tried a "puts doc" next, and it printed the document. - -- David Morton Maia Mailguard - http://www.maiamailguard.com Morton Software Design and Consulting - http://www.dgrmm.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEU4FsSIxC85HZHLMRAozKAJ0akKo+TjVLGoC1VsRw9e99W77D/gCeJ3zy T8t/vLmHgZVx+Gt1wSOlPZU=Q350 -----END PGP SIGNATURE-----
On 4/29/06, David Morton <mortonda at dgrmm.net> wrote:> > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Bill Walton wrote: > > > irb(main):003:0> doc=REXML::Document.new file > > => <UNDEFINED> ... </> > > [BW] I assume the <UNDEFINED> error message above is referring to > > Document. One thing I don''t understand though is why the ''require'' on > > I don''t think that''s an error, I think <UNDEFINED> is part of the XML > object. > Irb tries to output some descriptive text about the object. So this is > normal. > > Indeed, I tried a "puts doc" next, and it printed the document. >Yes, David is correct. I tried "doc.methods" and got a nice list of all the REXML Document methods. Curt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/instantrails-users/attachments/20060429/403da6f5/attachment.htm
Curt, David, Gavin; Thanks guys. I got thrown by the <UNDEFINED> output. It''s not shown in the tutorial so I figured it was an error of some sort. You''re all right. After reading Gavin''s response (because it came in first) I restarted and just kept going and everything works fine. It turns out, though, that the <UNDEFINED> output isn''t the only thing irb is outputting that''s not in the tutorial. I *hate* it when that happens ;-| Anyway, now that I can see how it works, I''m on to using RoR to do a little test app. Read in an XML file using REXML, store the contents in the db, then use Builder to write out a copy. Thanks again, Bill ----- Original Message ----- From: Curt Hibbs To: instantrails-users at rubyforge.org Sent: Saturday, April 29, 2006 10:52 AM Subject: Re: [Instantrails-users] REXML question On 4/29/06, David Morton <mortonda at dgrmm.net> wrote: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Bill Walton wrote: > irb(main):003:0> doc=REXML::Document.new file > => <UNDEFINED> ... </> > [BW] I assume the <UNDEFINED> error message above is referring to > Document. One thing I don''t understand though is why the ''require'' on I don''t think that''s an error, I think <UNDEFINED> is part of the XML object. Irb tries to output some descriptive text about the object. So this is normal. Indeed, I tried a "puts doc" next, and it printed the document. Yes, David is correct. I tried "doc.methods" and got a nice list of all the REXML Document methods. Curt ------------------------------------------------------------------------------ _______________________________________________ Instantrails-users mailing list Instantrails-users at rubyforge.org http://rubyforge.org/mailman/listinfo/instantrails-users -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/instantrails-users/attachments/20060429/c31c6573/attachment-0001.htm
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Bill Walton wrote:> Curt, David, Gavin; > > Thanks guys. I got thrown by the <UNDEFINED> output. It''s not shown in > the tutorial so I figured it was an error of some sort. You''re all > right. After reading Gavin''s response (because it came in first) I > restarted and just kept going and everything works fine. It turns out, > though, that the <UNDEFINED> output isn''t the only thing irb > is outputting that''s not in the tutorial. I *hate* it when that happens ;-|Did the tutorial even mention irb? That''s a normal side effect of irb. Since it is interactive, it gives you lots of output. A normal program run from a file won''t have any of that output. - -- David Morton Maia Mailguard - http://www.maiamailguard.com Morton Software Design and Consulting - http://www.dgrmm.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEU5gASIxC85HZHLMRApGqAJ0TJEhUyWIF5C/FBLkgdZFQvnRHmACfSmif V28LqJhlmP2rg9H7Jo2P/pw=/9v1 -----END PGP SIGNATURE-----
Hi David, David Morton wrote:> > Did the tutorial even mention irb? That''s a normal > side effect of irb. Since it is interactive, it gives you > lots of output. A normal program run from a file > won''t have any of that output.No, it didn''t actually. I guess I inferred that from the box in the article titled "Accessing Elements". It lookes like command line input / output. The tutorial''s at http://www.germane-software.com/software/rexml/docs/tutorial.html in case you want to see. I thought maybe he was using a *nix box or something. Just a good lesson for me, I guess, re: how to write a tutorial that confuses an audience of newbies ;-) Thanks again, Bill
On 4/30/06, Bill Walton <bill.walton at charter.net> wrote:> > > > Did the tutorial even mention irb? That''s a normal > > side effect of irb. Since it is interactive, it gives you > > lots of output. A normal program run from a file > > won''t have any of that output. > > No, it didn''t actually. I guess I inferred that from the box in the article > titled "Accessing Elements". It lookes like command line input / output. > The tutorial''s at > http://www.germane-software.com/software/rexml/docs/tutorial.html in case > you want to see. I thought maybe he was using a *nix box or something. > Just a good lesson for me, I guess, re: how to write a tutorial that > confuses an audience of newbies ;-)Don''t worry, Bill. Once you''ve worked through this tutorial and gained some more experience with how Ruby and IRB work, things like this won''t trouble you anymore. What Sean has done in the tutorial is use a normal Ruby convention for displaying the (expected) output of various lines of code. That is: code # -> output or code # -> output Many people use => instead of ->, but I prefer the latter, and so does Sean, apparently. When showing the expected output, one wants to be brief. You don''t show the output for every single line of code (the doc = Document.new file output wasn''t given because it''s part of "uninteresting" setup code) and you abbreviate the output just to get the point across. Showing a whole IRB transcript would have helped you but it''s too verbose for the purpose of the tutorial. The moral of the story? If you think you''ve hit a snag, investigate. Copy the following function into your IRB session (or IRB configuration file -- is it $HOME/_irbrc?): def hlp(obj=nil) # Note: not "help" which is an IRB reserved word (I think). if obj puts (obj.methods - Object.new.methods).sort else puts obj.methods.sort end end Then, if you don''t know what an object is (like "doc"), hlp doc will list all of doc''s methods, except the trivial ones. The following can also be useful: doc.class require ''yaml'' puts doc.to_yaml Google "irb tips and tricks" for more. Cheers, Gavin