[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: humanized Xml tree navigation

Pedro Côrte-Real

7/31/2006 1:33:00 PM

On 7/31/06, chiaro scuro <kiaroskuro@gmail.com> wrote:
> Does anybody know of a library that allows to go through an xml tree as if
> it were made of normal objects?
>
> I have seen e4x on rubyforge, but it doesn't seem to work. simplexml returns
> hashes rather than employing dynamic method calls
>
> What I need to do is to be able to traverse an xml document as in:
>
> * people.each_person {...}
> * people.person[2].name
> * people.person.name #takes the first person
> * people.person.size

My xmlcodec project will do this but you'll need to write some simple
classes to do it. For this case, something like:

class PeopleFormat < XMLElement
xmlformat 'People Format'
end

class People < PeopleFormat
elname :people
xmlsubel_mult :person
end

class Person < PeopleFormat
elname :person
xmlattr :name
xmlattr :size
end

With this you can do:

people = PeopleFormat.import_xml_text(myXMLTextOrFile)
people.person.each {|p| ...}
people.person.first.name
people.person[2].type

You can find it at http://xmlcodec.rub...

Cheers,

Pedro.

2 Answers

ptkwt

7/31/2006 10:05:00 PM

0

In article <62e8012c0607310632hb44a0b6md149d6462d20130c@mail.gmail.com>,
Pedro Côrte-Real <pedro@pedrocr.net> wrote:
>On 7/31/06, chiaro scuro <kiaroskuro@gmail.com> wrote:
>> Does anybody know of a library that allows to go through an xml tree as if
>> it were made of normal objects?
>>
>> I have seen e4x on rubyforge, but it doesn't seem to work. simplexml returns
>> hashes rather than employing dynamic method calls
>>
>> What I need to do is to be able to traverse an xml document as in:
>>
>> * people.each_person {...}
>> * people.person[2].name
>> * people.person.name #takes the first person
>> * people.person.size
>
>My xmlcodec project will do this but you'll need to write some simple
>classes to do it. For this case, something like:
>
>class PeopleFormat < XMLElement
> xmlformat 'People Format'
>end
>
>class People < PeopleFormat
> elname :people
> xmlsubel_mult :person
>end
>
>class Person < PeopleFormat
> elname :person
> xmlattr :name
> xmlattr :size
>end
>
>With this you can do:
>
>people = PeopleFormat.import_xml_text(myXMLTextOrFile)
>people.person.each {|p| ...}
>people.person.first.name
>people.person[2].type
>
>You can find it at http://xmlcodec.rub...
>

Nice. I've done this sort of thing, but much more 'manually' than you
show here.

Phil

mbottorff

1/30/2009 2:39:00 PM

0

Irina Rempt <irina@valdyas.org> wrote:

> On Friday 30 January 2009 05:20, Ben Crowell wrote:
>
> > Step 1: I wrote this great story!
> >
> > Step 2: I find out there are problems with the story, typically because
> > my wife tells me so.
> >
> > Step 3: I deny that there are problems. I submit the story.
> >
> > Step 4: I get comments from editors saying the same things my wife
> > said.
> >
> > Step 5: I revise the story.
>
> Whereas I tend go straight from (1) to (5) and get stuck there, mostly
> because I do all the (2) and (4) stuff myself, far too well to ever
> attempt (3).

I'm sure y'all know this, but just as a reminder...

The proper procedure is to go 1, 2, 5, 3.

You can skip straight from 1 to 3 if you have no immediate access to 2.
But making an honest attempt to achieve 2 is highly recommended.

Hitting 3 immediately following either step 2 or 4 is usually
counter-productive.

Failure to hit 3, however, is a death sentence to any ambition you may
have to get the story published. Whenever I am tempted to skip step 3
(which is frequently) I remind myself of that fact.

You're allowed to go back to 5 only after arriving at 4 (editorial
feedback)... or running out of editors to try in an attempt to hit 4.



--
Michelle Bottorff -> Chelle B. -> Shelby
L. Shelby, Writer http://www.ls...
Livejournal http://lavenderbard.livejo...
rec.arts.sf.composition FAQ http://www.ls...rasfcFAQ.html