From: Lance Pollard on
Hey,

Is there a way to organize/print out the xml attributes using Hpricot,
or do I have to run through the xml file again and replace patterns?

I would like to be able to say "put this attribute first, put this
attribute next ...", so I can say, I want this:

<node id="name" property="value"/>

not this:

<node property="value" id="name"/>

Since the attributes are kept in a hash there's no order to them, so
they appear in seemingly random order, but it's the same random order
consistently.

Any ideas how to do that?

And is there a way to say "after two attributes, make a new line". So I
can print out xml that can be edited by humans like code.

Thanks,
Lance
--
Posted via http://www.ruby-forum.com/.

From: Axel Etzold on
Dear Lance,

>
> Since the attributes are kept in a hash there's no order to them, so
> they appear in seemingly random order, but it's the same random order
> consistently.
>
> Any ideas how to do that?
>

a Hash can be sorted to give an Array with Hash#sort :

http://ruby-doc.org/core/classes/Hash.html#M002865


> And is there a way to say "after two attributes, make a new line". So I
> can print out xml that can be edited by humans like code.

You can then iterate through the Array with Array#each_with_index,
eg.

my_array.each_with_index{|x,i|





>
> Thanks,
> Lance
> --
> Posted via http://www.ruby-forum.com/.

--
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser

From: Axel Etzold on
Dear Lance,

I accidentally hit the "send" button too early:

>
> Since the attributes are kept in a hash there's no order to them, so
> they appear in seemingly random order, but it's the same random order
> consistently.
>
> Any ideas how to do that?
>

a Hash can be sorted to give an Array with Hash#sort :

http://ruby-doc.org/core/classes/Hash.html#M002865


> And is there a way to say "after two attributes, make a new line". So I
> can print out xml that can be edited by humans like code.

You can then iterate through the Array with Array#each_with_index,
eg.

my_array.each_with_index{|x,i| if i%2==0 ; p x + "\n"; else p x; end}

Best regards,

Axel




--
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
f�r nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02

From: Lance Pollard on
Thanks a lot axel, I'll give these a try

Best,
Lance

Axel Etzold wrote:
> Dear Lance,
>
> I accidentally hit the "send" button too early:
>
>>
>> Since the attributes are kept in a hash there's no order to them, so
>> they appear in seemingly random order, but it's the same random order
>> consistently.
>>
>> Any ideas how to do that?
>>
>
> a Hash can be sorted to give an Array with Hash#sort :
>
> http://ruby-doc.org/core/classes/Hash.html#M002865
>
>
>> And is there a way to say "after two attributes, make a new line". So I
>> can print out xml that can be edited by humans like code.
>
> You can then iterate through the Array with Array#each_with_index,
> eg.
>
> my_array.each_with_index{|x,i| if i%2==0 ; p x + "\n"; else p x; end}
>
> Best regards,
>
> Axel

--
Posted via http://www.ruby-forum.com/.

From: Lance Pollard on
This means though I have to do two passes on the XML:

1) Modify the nodes with data the way nokogiri or hpricot do it (xpath
and whatnot)
2) Format the xml using regular expression on pure strings, not using
the xml parsing engines.

Is that correct?

Thanks,
Lance
--
Posted via http://www.ruby-forum.com/.

 |  Next  |  Last
Pages: 1 2
Prev: ruby-oci8 function
Next: xmlrpc