[ANN] XMLable 0.1.1


R

Rolando Abarca

--Apple-Mail-7--1032220225
Content-Type: multipart/alternative; boundary=Apple-Mail-6--1032220265


--Apple-Mail-6--1032220265
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=WINDOWS-1252;
delsp=yes;
format=flowed

As we all need more free stuff that does the same*, here's another =20
XML serialization library:

XMLable 0.1.1

Some copy-paste from the docs:

Simple, and I mean really-simple, non-secure way to convert ruby =20
objects to/from XML data.
(ok, right now is really simple and maybe not really non-secure, but =20
it doesn=91t mean it can=91t be a bit more "secure" in the future :p)
Just make sure that your class includes the XMLable module and the =20
constructor has only one parameter: a Hash with String keys for each =20
attribute you want to setup on initialization.
You can also use the utility function init_attributes_with_opts to =20
initialize the attributes (check the doc)
Oh, also, XMLable depends on REXML, so make sure you require =20
somewhere in your code =91rexml/document=92.

Now, for the fun, some irb tricks:

irb(main):001:0> require 'xmlable'
=3D> true
irb(main):002:0> require 'rexml/document'
=3D> true
irb(main):003:0> [1,2,3].to_xml
=3D> <rarray> ... </>
irb(main):004:0> [1,2,3].to_xml.to_s
=3D> "<rarray><ritem rclass=3D'Fixnum'>1</ritem><ritem =
rclass=3D'Fixnum'>2</=20
ritem><ritem rclass=3D'Fixnum'>3</ritem></rarray>"
irb(main):005:0> [1,Time.now,nil,["wow",:nice]].to_xml.to_s
=3D> said:
<ritem rclass=3D'Array'><rarray><ritem rclass=3D'String'>wow</=20
ritem><ritem rclass=3D'Symbol'>nice</ritem></rarray></ritem></rarray>"
irb(main):006:0> data =3D [1,nil,"lalala"].to_xml
=3D> <rarray> ... </>
irb(main):007:0> Array.from_xml(data)
=3D> [1, nil, "lalala"]
irb(main):008:0> Array.from_xml(data.to_s)
=3D> [1, nil, "lalala"]
irb(main):009:0> data =3D {:hey =3D> "thisisfun", ["right","?"] =3D> =
nil}
=3D> {["right", "?"]=3D>nil, :hey=3D>"thisisfun"}
irb(main):010:0> Hash.from_xml(data.to_xml)
=3D> {["right", "?"]=3D>nil, :hey=3D>"thisisfun"}
irb(main):011:0> module A
irb(main):012:1> module B
irb(main):013:2> class C
irb(main):014:3> include XMLable
irb(main):015:3> def initialize(opts)
irb(main):016:4> init_attributes_with_opts({"lala" =3D> 10}, opts)
irb(main):017:4> end
irb(main):018:3> end
irb(main):019:2> end
irb(main):020:1> end
=3D> nil
irb(main):021:0> c =3D A::B::C.new({"lala" =3D> 5400})
=3D> #<A::B::C:0x22ffa8 @lala=3D5400>
irb(main):022:0> c.to_xml.to_s
=3D> "<robject rclass=3D'A::B::C'><rattr name=3D'lala' =20
rclass=3D'Fixnum'>5400</rattr></robject>"
irb(main):023:0> another_c =3D A::B::C.from_xml(c.to_xml)
=3D> #<A::B::C:0x229298 @lala=3D5400>
irb(main):024:0> data =3D ["check",:this,c].to_xml.to_s
=3D> "<rarray><ritem rclass=3D'String'>check</ritem><ritem =20
rclass=3D'Symbol'>this</ritem><ritem rclass=3D'A::B::C'><robject =20
rclass=3D'A::B::C'><rattr name=3D'lala' rclass=3D'Fixnum'>5400</rattr></=20=

robject></ritem></rarray>"
irb(main):025:0> Array.from_xml(data)
=3D> ["check", :this, #<A::B::C:0x21d4c0 @lala=3D5400>]

You can get it here (source and tests):

http://rolando.cl/ruby/xmlable/src/xmlable.rb
http://rolando.cl/ruby/xmlable/src/test.rb

and the doc:

http://rolando.cl/ruby/xmlable/doc/index.html

* I just was lazy searching for some library, and because I was =20
bored, I ended up writing my own library... :p

Enjoy!
--=20
Rolando Abarca
Phone: +56-9 97851962



--Apple-Mail-6--1032220265
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=WINDOWS-1252

<HTML><BODY style=3D"word-wrap: break-word; -khtml-nbsp-mode: space; =
-khtml-line-break: after-white-space; ">As we all need more free stuff =
that does the same*, here's another XML serialization library:<DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>XMLable =
0.1.1</DIV><DIV><DIV><BR class=3D"khtml-block-placeholder"></DIV><DIV>Some=
copy-paste from the docs:</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Simple, and I =
mean really-simple, non-secure way to convert ruby objects to/from XML =
data.</DIV><DIV style=3D"margin-top: 0px; margin-right: 0px; =
margin-bottom: 0px; margin-left: 0px; ">(ok, right now is really simple =
and maybe not really non-secure, but it doesn=91t mean it can=91t be a =
bit more "secure" in the future :p)</DIV><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Just make =
sure that your class includes the XMLable module and the constructor has =
only one parameter: a Hash with String keys for each attribute you want =
to setup on initialization.</DIV><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">You can also =
use the utility function init_attributes_with_opts to initialize the =
attributes (check the doc)</DIV><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Oh, also, =
XMLable depends on REXML, so make sure you require somewhere in your =
code =91rexml/document=92.</DIV><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 12px/normal Helvetica; min-height: 14px; "><BR></DIV><DIV =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; ">Now, for the fun, some irb tricks:</DIV><DIV =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; "><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>irb(main):001:0&gt; require =
'xmlable' </DIV><DIV>=3D&gt; true</DIV><DIV>irb(main):002:0&gt; require =
'rexml/document'</DIV><DIV>=3D&gt; true</DIV><DIV>irb(main):003:0&gt; =
[1,2,3].to_xml</DIV><DIV>=3D&gt; &lt;rarray&gt; ... =
&lt;/&gt;</DIV><DIV>irb(main):004:0&gt; =
[1,2,3].to_xml.to_s</DIV><DIV>=3D&gt; "&lt;rarray&gt;&lt;ritem =
rclass=3D'Fixnum'&gt;1&lt;/ritem&gt;&lt;ritem =
rclass=3D'Fixnum'&gt;2&lt;/ritem&gt;&lt;ritem =
rclass=3D'Fixnum'&gt;3&lt;/ritem&gt;&lt;/rarray&gt;"</DIV><DIV>irb(main):0=
05:0&gt; [1,Time.now,nil,["wow",:nice]].to_xml.to_s</DIV><DIV>=3D&gt; =
"&lt;rarray&gt;&lt;ritem rclass=3D'Fixnum'&gt;1&lt;/ritem&gt;&lt;ritem =
rclass=3D'Time'&gt;1187725687.81283&lt;/ritem&gt;&lt;ritem =
rclass=3D'NilClass'/&gt;&lt;ritem =
rclass=3D'Array'&gt;&lt;rarray&gt;&lt;ritem =
rclass=3D'String'&gt;wow&lt;/ritem&gt;&lt;ritem =
rclass=3D'Symbol'&gt;nice&lt;/ritem&gt;&lt;/rarray&gt;&lt;/ritem&gt;&lt;/r=
array&gt;"</DIV><DIV>irb(main):006:0&gt; data =3D =
[1,nil,"lalala"].to_xml</DIV><DIV>=3D&gt; &lt;rarray&gt; ... =
&lt;/&gt;</DIV><DIV>irb(main):007:0&gt; =
Array.from_xml(data)</DIV><DIV>=3D&gt; [1, nil, =
"lalala"]</DIV><DIV>irb(main):008:0&gt; =
Array.from_xml(data.to_s)</DIV><DIV>=3D&gt; [1, nil, =
"lalala"]</DIV><DIV>irb(main):009:0&gt; data =3D {:hey =3D&gt; =
"thisisfun", ["right","?"] =3D&gt; nil}</DIV><DIV>=3D&gt; {["right", =
"?"]=3D&gt;nil, :hey=3D&gt;"thisisfun"}</DIV><DIV>irb(main):010:0&gt; =
Hash.from_xml(data.to_xml)</DIV><DIV>=3D&gt; {["right", "?"]=3D&gt;nil, =
:hey=3D&gt;"thisisfun"}</DIV><DIV>irb(main):011:0&gt; module =
A</DIV><DIV>irb(main):012:1&gt; module B</DIV><DIV>irb(main):013:2&gt; =
class C</DIV><DIV>irb(main):014:3&gt; include =
XMLable</DIV><DIV>irb(main):015:3&gt; def =
initialize(opts)</DIV><DIV>irb(main):016:4&gt; =
init_attributes_with_opts({"lala" =3D&gt; 10}, =
opts)</DIV><DIV>irb(main):017:4&gt; end</DIV><DIV>irb(main):018:3&gt; =
end</DIV><DIV>irb(main):019:2&gt; end</DIV><DIV>irb(main):020:1&gt; =
end</DIV><DIV>=3D&gt; nil</DIV><DIV>irb(main):021:0&gt; c =3D =
A::B::C.new({"lala" =3D&gt; 5400})</DIV><DIV>=3D&gt; =
#&lt;A::B::C:0x22ffa8 @lala=3D5400&gt;</DIV><DIV>irb(main):022:0&gt; =
c.to_xml.to_s</DIV><DIV>=3D&gt; "&lt;robject =
rclass=3D'A::B::C'&gt;&lt;rattr name=3D'lala' =
rclass=3D'Fixnum'&gt;5400&lt;/rattr&gt;&lt;/robject&gt;"</DIV><DIV>irb(mai=
n):023:0&gt; another_c =3D A::B::C.from_xml(c.to_xml)</DIV><DIV>=3D&gt; =
#&lt;A::B::C:0x229298 @lala=3D5400&gt;</DIV><DIV>irb(main):024:0&gt; =
data =3D ["check",:this,c].to_xml.to_s</DIV><DIV>=3D&gt; =
"&lt;rarray&gt;&lt;ritem rclass=3D'String'&gt;check&lt;/ritem&gt;&lt;ritem=
rclass=3D'Symbol'&gt;this&lt;/ritem&gt;&lt;ritem =
rclass=3D'A::B::C'&gt;&lt;robject rclass=3D'A::B::C'&gt;&lt;rattr =
name=3D'lala' =
rclass=3D'Fixnum'&gt;5400&lt;/rattr&gt;&lt;/robject&gt;&lt;/ritem&gt;&lt;/=
rarray&gt;"</DIV><DIV>irb(main):025:0&gt; =
Array.from_xml(data)</DIV><DIV>=3D&gt; ["check", :this, =
#&lt;A::B::C:0x21d4c0 @lala=3D5400&gt;]</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>You can get it here (source =
and tests):</DIV><DIV><BR class=3D"khtml-block-placeholder"></DIV><DIV><A =
href=3D"http://rolando.cl/ruby/xmlable/src/xmlable.rb">http://rolando.cl/r=
uby/xmlable/src/xmlable.rb</A></DIV><DIV><A =
href=3D"http://rolando.cl/ruby/xmlable/src/test.rb">http://rolando.cl/ruby=
/xmlable/src/test.rb</A></DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>and the doc:</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV><A =
href=3D"http://rolando.cl/ruby/xmlable/doc/index.html">http://rolando.cl/r=
uby/xmlable/doc/index.html</A></DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>* I just was lazy searching =
for some library, and because I was bored, I ended up writing my own =
library... :p</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>Enjoy!<BR><DIV> <SPAN =
class=3D"Apple-style-span" style=3D"border-collapse: separate; =
border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; =
font-size: 12px; font-style: normal; font-variant: normal; font-weight: =
normal; letter-spacing: normal; line-height: normal; text-align: auto; =
-khtml-text-decorations-in-effect: none; text-indent: 0px; =
-apple-text-size-adjust: auto; text-transform: none; orphans: 2; =
white-space: normal; widows: 2; word-spacing: 0px; =
"><DIV>--=A0</DIV><DIV>Rolando Abarca</DIV><DIV>Phone: +56-9 =
97851962</DIV><BR class=3D"Apple-interchange-newline"></SPAN> =
</DIV><BR></DIV></DIV></BODY></HTML>=

--Apple-Mail-6--1032220265--

--Apple-Mail-7--1032220225
content-type: application/pgp-signature; x-mac-type=70674453;
name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)

iD8DBQFGy0v59fOunnYODS4RAtYHAJ9XsL2GQ32k3uWxjYpS01OHHmW5UQCgrIaZ
XdbiyPPlFxDmpQEBJC5gUOM=
=sRAp
-----END PGP SIGNATURE-----

--Apple-Mail-7--1032220225--
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top