xml + ruby = happy programmer

P

paul vudmaska

--- James Britt said:
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.

Wish i'd seen that thread awhile ago, thank you
:)
so it's item #1<<

perfect. it works good now but could be closer to
ruby.
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.
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.
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.

Probably. I hope it can conform to ruby ;)
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.
The ruby way or the highway. :)
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.
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
 
B

Ben Giddings

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

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
 
P

Phil Tomson

#(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"
 
J

Joel VanderWerf

Ben said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top