xml + ruby = happy programmer

Discussion in 'Ruby' started by paul vudmaska, Oct 2, 2003.

  1. --- James Britt <> wrote:
    > paul vudmaska wrote:
    >
    > >
    > > My point is that that ruby might benefit from an

    > xml
    > > type,

    >
    >
    > It already does: String.

    Nope.

    > Do you mean special type that defines a (presumably
    > W3C) XML DOM,
    > *other* than a REXML Document?


    Yes! REXML, supporting a quasi / ruby friendly DOM.

    > See http://www.rubygarden.org/ruby?XMLinRuby
    >
    > James Britt


    Wish i'd seen that thread awhile ago, thank you
    :)

    >>Most peoples' top priority is something like REXML,

    so it's item #1<<

    perfect. it works good now but could be closer to
    ruby.

    >>What is meant when people refer to "XML"?

    To me it means a stream of parsable tokens that any
    xml parser wont die over. The api for getting that
    data is sorta up in the air but rexml is far better
    than any i've encountered (heavy on the ms side and
    some javugly). The rexml site sums this up nicely.

    >> What exactly is meant by "handle XML out of the

    box"? <<
    I mean something like this...

    #(presuming %x creates an xml literal.)
    x = %x{<m><l>is your friend</l></m>}

    #access it like this...
    print x.m.l #>is your friend

    as opposed to
    x = {'m'=>{'l'=>'is your friend'}}

    print x['m']['l']#something like that.

    I'm not a ruby guru and might not even be that good a
    programmer but i like the first better. Much.

    >>Will it mean the same thing to XML developers coming

    to Ruby as it does to Ruby developers looking to work
    with XML? <<

    Accept the api will be better since it is ruby. It's
    just another tool. A way to create data structures. Of
    any type.

    Coming from both Asp Javascript(which has great xml
    support but the api is not as awesome as rexml) and
    PHP, whose xml api you can keep, i was anxious to find
    a user friendly xml api. And then there was REXML.
    That and finding e4x, prompted this thread.


    >>Is there an "XML way"?<<

    Probably. I hope it can conform to ruby ;)

    >>Who are the end users?<<

    ME!Developers, but, subtly, its use brings it closer
    to users as well, for the same reason templates have
    gotten so popular. And html for that matter.

    >>What are the requirements?<<

    The ruby way or the highway. :)

    >>What are the time constraints? <<

    REXML is fine and dandy now and for the foreseable
    future, but strategically, it should be heavily
    considered, pondered, kicked around, imo. And be ready
    for production tommorrow.

    >>[It should] features full XPath <<

    Yes for more sophisticated queries that are not well
    supported by a simple api. For instance multiple
    changes of context and subqueries.

    >>SAX<< ...most helpful(necessary) for heavy sets, if

    it's that heavy maybe another means would be better
    than having 2 apis. But maybe not ;)

    And then there is native Xsl(not really xsl but
    programic styling of data,

    http://martinfowler.com/bliki/movingAwayFromXslt.html

    that hopefully, gleans some of xsl's benefits without
    its verbosity or syntax). But i'll start that flame
    war another day. Its been fun.

    pv




    __________________________________
    Do you Yahoo!?
    The New Yahoo! Shopping - with improved product search
    http://shopping.yahoo.com
     
    paul vudmaska, Oct 2, 2003
    #1
    1. Advertising

  2. paul vudmaska

    Ben Giddings Guest

    paul vudmaska wrote:
    > I mean something like this...
    >
    > #(presuming %x creates an xml literal.)
    > x = %x{<m><l>is your friend</l></m>}
    >
    > #access it like this...
    > print x.m.l #>is your friend
    >
    > as opposed to
    > x = {'m'=>{'l'=>'is your friend'}}
    >
    > print x['m']['l']#something like that.
    >
    > I'm not a ruby guru and might not even be that good a
    > programmer but i like the first better. Much.


    How do you propose to handle an element like:

    <xsl:import href="..."/>

    The set of allowable characters in an XML element is larger than the set of
    allowable characters in a Ruby method name:

    http://www.w3.org/TR/REC-xml#NT-NameChar

    As for x = %x{<m><l>is your friend</l></m>}

    There was recently a long discussion on this list about new "percent letter
    brace" tricks. I think the general feeling was that it was simpler to just
    create a method that takes a string as an argument and returns an XML element.

    I don't know if there are any methods that do that, but how would you feel
    about:

    x = XMLParser.parse "<m><l>is your friend</l></m>"

    If that's too wordy, you could always say:

    def xml(arg)
    XMLParser.parse(arg)
    end

    x = xml "<m><l>is your friend</l></m>"

    Ben
     
    Ben Giddings, Oct 3, 2003
    #2
    1. Advertising

  3. paul vudmaska

    Phil Tomson Guest

    In article <>,
    paul vudmaska <> wrote:
    >--- James Britt <> wrote:
    >> paul vudmaska wrote:

    >
    >#(presuming %x creates an xml literal.)
    >x = %x{<m><l>is your friend</l></m>}
    >
    >#access it like this...
    >print x.m.l #>is your friend
    >


    Why the lucky stiff made a patch to do something like this with YAML using

    From his site (http://whytheluckystiff.net):
    "%y:

    %y{ ... }

    I've been having a lot of fun with this Ruby 1.8.0 hack. This patch adds
    the %y{ ... } construct to Ruby. This way, you can embed YAML directly in
    your Ruby script.

    basic_map = %y{
    --- !omap
    - one: foo
    - two: bar
    - three: baz
    }

    Kinda cool, eh?

    Try:

    patch -p1 -d ~/src/ruby-1.8.0 < ruby-1.8.0-yamlstr.patch"
     
    Phil Tomson, Oct 3, 2003
    #3
  4. Ben Giddings wrote:

    > The set of allowable characters in an XML element is larger than the set
    > of allowable characters in a Ruby method name:


    Actually, Ruby method names are pretty general (but I still agree with
    your point)...

    irb(main):006:0> x=[]
    => []
    irb(main):008:0> class << x; define_method :"&%(@)%&@" do puts "Hi."
    end; end
    => #<Proc:0x401fbfac@(irb):8>
    irb(main):009:0> x.send :"&%(@)%&@"

    Hi.
    => nil
     
    Joel VanderWerf, Oct 3, 2003
    #4
    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. Sanny
    Replies:
    391
    Views:
    42,038
    anish.mathew84
    Jan 6, 2010
  2. Sanny
    Replies:
    396
    Views:
    7,154
    Noah Roberts
    Dec 17, 2008
  3. Isaac
    Replies:
    0
    Views:
    397
    Isaac
    Dec 8, 2010
  4. Daniel Martin
    Replies:
    1
    Views:
    177
    Daniel Martin
    Sep 6, 2006
  5. James Edward Gray II

    Happy Programmer's Day!

    James Edward Gray II, Sep 13, 2006, in forum: Ruby
    Replies:
    6
    Views:
    114
    James Britt
    Sep 14, 2006
Loading...

Share This Page