P
paul vudmaska
The biggest problem i have with Ruby is the sleepness
nights.... ;->
Has anyone heard of e4x...emcascript(aka javascript)
for xml?
http://dev2dev.bea.com/products/wlworkshop/articles/JSchneider_XML.jsp
Basically it is an attempt to roll xml as a native
type into ecmascript. I'd suggest Ruby could benefit
and set itself apart by doing so. Following is my own
quick and dirty Ruby'd version of the above.(you might
want to check it out first)
# xml literal...
p = %x{<Peeps><P>paul</P><P>john</P><P/></Peeps>}
or
p <<<XML
<Peeps>
<P>paul</P>
<P>john</P>
<P/>
</Peeps>
XML
#access
mary = p.Peeps.P[3]#xpath starts with 1...
#edit
mary = 'mary'#convenience method appending text to P
element
#add element
p.Peeps << %x{<P>Ringo</P>}
#iter.
p.Peeps.each('P') do |person|
puts person #>paul,john,mary,ringo
end
Instead of the dot notation for swiching context
suggested in the above article, perhaps use xpath
exclusively,imo.
p.each('//P') do ...end
So, basically, rexml rolled into ruby natively.
But what about the much maligned xsl stylesheets? We
need style too - Rubystyle!
# prob a million ways to do this...
style = <<<STYLE
<div>
<h1>#{P}</h1> is a rock star
</div>
STYLE
...here's one
output = p.each('//P').transform(style)
There's plenty of room for rolling more
organic/programic/rubylike approaches to style than
xsl into Ruby(particulary considering Ruby's iters and
blocks). I'm not sure this is the wisest approach, and
think people like Michael Kay(an xsl guru) might point
out the folly of this. And keeping to a standard would
be good for a product such as Ruby but it sure is
intersting...at least to me.
So now we've
1) done what javascript might be doing but totally
trumped them with (ruby)style.
2) added a feature that python and perl can only wish
for
3) created an internal common data structure that is
similar to the array, hash and struct but is sometimes
better and certainly more portable/readable.
4) now a native type, we can import/export data to
whatever speaks xml without worrying about
implementation.
5) have an inherent mechanism for seperating duties
<important>within code</important>- ie data from style
6)a powerful native templating system. Great for web
stuff particularily. Picture putting the power of ruby
in templates that are sandboxed. No need to learn
template language X. Do it in ruby or subset of.
6+) prob much more, xml tends to feed upon itself
Whatcha think? Can i count on this by 1.8.1? ;->
v
PS:as for the previous comment at artima about the
limitations of Ruby - stone that guy! Not really-
seemed like legit points 2me. I want Ruby to scale to
1 mil hits per sec on my ipaq too - but not at the
expense of creativity, malability, fidelity,
pragmatism or effectiveness.
__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
nights.... ;->
Has anyone heard of e4x...emcascript(aka javascript)
for xml?
http://dev2dev.bea.com/products/wlworkshop/articles/JSchneider_XML.jsp
Basically it is an attempt to roll xml as a native
type into ecmascript. I'd suggest Ruby could benefit
and set itself apart by doing so. Following is my own
quick and dirty Ruby'd version of the above.(you might
want to check it out first)
# xml literal...
p = %x{<Peeps><P>paul</P><P>john</P><P/></Peeps>}
or
p <<<XML
<Peeps>
<P>paul</P>
<P>john</P>
<P/>
</Peeps>
XML
#access
mary = p.Peeps.P[3]#xpath starts with 1...
#edit
mary = 'mary'#convenience method appending text to P
element
#add element
p.Peeps << %x{<P>Ringo</P>}
#iter.
p.Peeps.each('P') do |person|
puts person #>paul,john,mary,ringo
end
Instead of the dot notation for swiching context
suggested in the above article, perhaps use xpath
exclusively,imo.
p.each('//P') do ...end
So, basically, rexml rolled into ruby natively.
But what about the much maligned xsl stylesheets? We
need style too - Rubystyle!
# prob a million ways to do this...
style = <<<STYLE
<div>
<h1>#{P}</h1> is a rock star
</div>
STYLE
...here's one
output = p.each('//P').transform(style)
There's plenty of room for rolling more
organic/programic/rubylike approaches to style than
xsl into Ruby(particulary considering Ruby's iters and
blocks). I'm not sure this is the wisest approach, and
think people like Michael Kay(an xsl guru) might point
out the folly of this. And keeping to a standard would
be good for a product such as Ruby but it sure is
intersting...at least to me.
So now we've
1) done what javascript might be doing but totally
trumped them with (ruby)style.
2) added a feature that python and perl can only wish
for
3) created an internal common data structure that is
similar to the array, hash and struct but is sometimes
better and certainly more portable/readable.
4) now a native type, we can import/export data to
whatever speaks xml without worrying about
implementation.
5) have an inherent mechanism for seperating duties
<important>within code</important>- ie data from style
6)a powerful native templating system. Great for web
stuff particularily. Picture putting the power of ruby
in templates that are sandboxed. No need to learn
template language X. Do it in ruby or subset of.
6+) prob much more, xml tends to feed upon itself
Whatcha think? Can i count on this by 1.8.1? ;->
v
PS:as for the previous comment at artima about the
limitations of Ruby - stone that guy! Not really-
seemed like legit points 2me. I want Ruby to scale to
1 mil hits per sec on my ipaq too - but not at the
expense of creativity, malability, fidelity,
pragmatism or effectiveness.
__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com