[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

Austin Ziegler

10/3/2003 7:10:00 PM

On Sat, 4 Oct 2003 00:17:01 +0900, Eric Hodel wrote:
> Austin Ziegler (austin@halostatue.ca) wrote:
>> There's further confusion if you had:
>> <list><item>1</item><item>2</item><item>3</item></list>

>> How would I refer to each individual item: list.item[0] through
>> list.item[2]? If the <list> tag also allowed for CDATA values, there's
>> nothing in the XML spec that would prevent:

>> <list>cdata<item>1</item>cdata<item>2</item>cdata</list>
> Ruby <--> XML seems to be a poor fit, it seems XML will quickly become
> too verbose with all the exceptions and having to resort to XPath (I've
> seen several posts that say "oh, we'll have to use XPath for that", and
> that wouldn't make me very happy). Ruby <--> RDF would be a better fit,
> especially if used as a serialization format.

I'm not sure I understand what you're saying, especially as RDF is an XML
format.

I've had good results with the use of REXML for XML processing. I don't do a
lot with XML, but I can't fault the API for that. REXML can, of course, be
used in either "DOM" or stream/SAX mode, and if the DOM mode is too verbose
for the purposes of processing, then the SAX mode can help -- I think.

-austin
--
austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.10.03
* 15.07.29



1 Answer

Eric Hodel

10/3/2003 9:19:00 PM

0

Austin Ziegler (austin@halostatue.ca) wrote:

> On Sat, 4 Oct 2003 00:17:01 +0900, Eric Hodel wrote:
> > Ruby <--> XML seems to be a poor fit, it seems XML will quickly become
> > too verbose with all the exceptions and having to resort to XPath (I've
> > seen several posts that say "oh, we'll have to use XPath for that", and
> > that wouldn't make me very happy). Ruby <--> RDF would be a better fit,
> > especially if used as a serialization format.
>
> I'm not sure I understand what you're saying, especially as RDF is an XML
> format.

The biggest problem I've seen above is that XML documents are just being
made up without any schemas or relationships to other documents. The
best thing about XML is the namespaces, because you can write <clothing:tie/>
and <rope:tie/> and know that the two are different contexts. (Even
though nobody seems to do that, which is a real shame.)

Unfortunately, there's no way to tell what way two different namespaces
are related to each other, and this is where RDF comes in.

RDF has an XML serialization format, but you can store RDF in any format
you want. RDF's strength is its focus on relationships, and what you
can infer from the ones given. Here's some RDF in subject, predicate,
object triples:

<urn:person:Sandra> -> name -> Sandra
<urn:person:Sandra> -> gender -> female
<urn:person:Sandra> -> sibling -> <urn:person:Kevin>
<urn:person:Kevin> -> name -> Kevin
<urn:person:Kevin> -> gender -> male
<urn:person:Kevin> -> parent -> <urn:person:Sarah>
<urn:person:Sarah> -> name -> Sarah
<urn:person:Sarah> -> gender -> female

With this data, you can easily infer that:

Sandra has a brother.
Sandra's mother's name is Sarah.
Sarah has at least two children.

And since everything can be given a namespace that maps back to the
basic RDF types, you can easily pass this information in and out of
other systems, and everybody will know what you are talking about.

Specifically, serializing Ruby objects in XML is a waste if only Ruby
can understand the generated XML. Nobody else can understand the
relationships and easily use them into other systems. Using RDF, the
relationships are easily parseable for use in other systems, making
them interoperable without pain.

> I've had good results with the use of REXML for XML processing. I don't do a
> lot with XML, but I can't fault the API for that. REXML can, of course, be
> used in either "DOM" or stream/SAX mode, and if the DOM mode is too verbose
> for the purposes of processing, then the SAX mode can help -- I think.

Yes, I agree everything I've done with REXML has been straightforward
and simple. I'm just pointing out that throwing XML into the midst of
things isn't going to necessarily give you any direct gains without a
bit of thought.

--
Eric Hodel - drbrain@segment7.net - http://se...
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04