[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

xml + ruby = happy programmer

paul vudmaska

10/2/2003 10:51:00 PM

--- James Britt <jamesUNDERBARb@seemyemail.com> 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...
>
> 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/movingAwayFro...

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...

4 Answers

Ben Giddings

10/3/2003 12:15:00 AM

0

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#N...

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


ptkwt

10/3/2003 12:17:00 AM

0

In article <20031002225021.59665.qmail@web10406.mail.yahoo.com>,
paul vudmaska <paul_vudmaska@yahoo.com> wrote:
>--- James Britt <jamesUNDERBARb@seemyemail.com> 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://whytheluck...):
"%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"

Ben Schumacher

10/3/2003 12:22:00 AM

0

paul vudmaska said:
> 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.

Sorry to focus on just this aspect of this post... this would never work.
How would I translate this element <element-name/> into this format?

## this
x = %x{<element-name>stuff</element-name>}
print x.element-name
## would evaluate to x.element (minus) name.

Unfortunately, the characters allow in element names don't allow this
"native" support. As a developer who uses XML daily, I find the current
interface extremely useful and powerful... especially with XPath. I don't
want to have to DOM grovel down two different elements, when I can just as
easily do: x['//i-need-this-one']

My 2c.

bs.

Joel VanderWerf

10/3/2003 12:22:00 AM

0

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