Question about REXML

Discussion in 'Ruby' started by Brad, Sep 19, 2008.

  1. Brad

    Brad Guest

    I'm trying to follow this tutorial: http://www.germane-software.com/software/rexml/docs/tutorial.html

    When I use the IRB and do:
    require "rexml/document"
    include REXML
    doc = Document.new File.new("mydoc.xml")

    I get an error:
    <UNDEFINED> ... </>

    I copied the source file right from the website and created an XML
    document called 'mydoc.xml'

    Why is it failing?

    Thank you

    Brad
    Brad, Sep 19, 2008
    #1
    1. Advertising

  2. Brad

    matt neuburg Guest

    Brad <> wrote:

    > When I use the IRB and do:
    > require "rexml/document"
    > include REXML
    > doc = Document.new File.new("mydoc.xml")
    >
    > I get an error:
    > <UNDEFINED> ... </>
    >
    > I copied the source file right from the website and created an XML
    > document called 'mydoc.xml'
    >
    > Why is it failing?


    It isn't. :) Say

    puts doc

    ....and you will see that all is well. m.

    --
    matt neuburg, phd = , http://www.tidbits.com/matt/
    Leopard - http://www.takecontrolbooks.com/leopard-customizing.html
    AppleScript - http://www.amazon.com/gp/product/0596102119
    Read TidBITS! It's free and smart. http://www.tidbits.com
    matt neuburg, Sep 19, 2008
    #2
    1. Advertising

  3. On 19.09.2008 20:33, Brad wrote:
    > I'm trying to follow this tutorial: http://www.germane-software.com/software/rexml/docs/tutorial.html
    >
    > When I use the IRB and do:
    > require "rexml/document"
    > include REXML
    > doc = Document.new File.new("mydoc.xml")
    >
    > I get an error:
    > <UNDEFINED> ... </>
    >
    > I copied the source file right from the website and created an XML
    > document called 'mydoc.xml'
    >
    > Why is it failing?


    As Matt said, it isn't. But you should make it a habit to properly
    close file handles; use any of these:

    doc = Document.new File.read("mydoc.xml")
    doc = File.open("mydoc.xml") {|io| Document.new(io)}
    doc = File.open("mydoc.xml", "rb") {|io| Document.new(io)}

    Kind regards

    robert
    Robert Klemme, Sep 20, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Damphyr
    Replies:
    2
    Views:
    137
    Damphyr
    Jul 16, 2003
  2. Ralph Mason
    Replies:
    2
    Views:
    85
    Ralph Mason
    Jan 13, 2004
  3. Han Holl

    Rexml xpath question

    Han Holl, Feb 22, 2004, in forum: Ruby
    Replies:
    7
    Views:
    138
    Han Holl
    Mar 6, 2004
  4. Daniel Berger

    rexml error - REXML::Validation

    Daniel Berger, Oct 12, 2004, in forum: Ruby
    Replies:
    2
    Views:
    150
    Henrik Horneber
    Oct 12, 2004
  5. Phlip
    Replies:
    0
    Views:
    140
    Phlip
    Jan 15, 2008
Loading...

Share This Page