[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: xml + ruby = happy programmer

paul vudmaska

10/3/2003 6:31:00 AM


--- Ben Giddings <bg-rubytalk@infofiend.com> wrote:
> 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="..."/>

One with a namespace ;/, i dont know, xpath maybe?

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

That is probably good. However in many cases with non
trivial xml, you'll want to indent. Maybe heredoc
notation as an option?

#rexml
doc = Document.new('<doc/>')
# and if it gets long
xml = << DOC
<toLong/>
DOC
doc = Document.new(xml)

I was thinking of a native literal. Mas o menos.

As per the dot notation, good question. I've can think
of no compelling reason to use it in xml off hand.

Only hackish things come to mind that dont seem ruby
like.

#fragment
w = <x.y><w/></x.y>
#maybe promoting the initial var.
w = x.y.w

So it looks as tho there's an extra element.
Ambiguous. Hmmmmm. Don't like/know. Maybe exclusively
relegated to xpath in that situation.

pv

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping...