.to_xml defined for Arrays, but not Strings? What?

Would anyone care to explain why the (censored) is .to_xml defined on
arrays (what? How do you do that? You separate the items by something?
By What? Or you repeat a tag? Which one?) and not for Strings? (Hey
dude, what’s the (censored) method to escape the data for inclusion in a
XMl string?

yeah I’m supposed to create a .rxml template (that’s about as far from a
template as you can get) and if I am clever enough and happen to find it
in the docs (very unlikely) I might even find out how to get my hands on
the XML in case I dare to want to write it somewhere instead of sending
it to the user behind the scenes after receiving a requeuest handled by
a controlllllller using the right magic. yeah, sweet.

Jenda

Oops, sorry.

require ‘rexml/document’
REXML::Text::normalize(…)

lovely. normalize(). Sure. Why not wrooblify()? When it comes to names
the Ruby folk is really inventive.

Jenda

Ignoring your rants:

Every conversion of ActiveRecord elements is also defined for arrays.
Array#to_xml sends to_xml to every element and throws an exception if an
element cannot answer. And: yes, to_xml has options on how to handle
this (seperations, wrappers, etc.).

If you search for Documentation on .rxml-Templates: Builder is the
library in use:

http://builder.rubyforge.org/

On the String#to_xml issue… XML code is a string, so this makes no
sense.

Hope that helps you… and calms you down.

Florian G. wrote:

Ignoring your rants:

Every conversion of ActiveRecord elements is also defined for arrays.
Array#to_xml sends to_xml to every element and throws an exception if an
element cannot answer. And: yes, to_xml has options on how to handle
this (seperations, wrappers, etc.).

If you search for Documentation on .rxml-Templates: Builder is the
library in use:

http://builder.rubyforge.org/

On the String#to_xml issue… XML code is a string, so this makes no
sense.

Hope that helps you… and calms you down.

“sdf<sorry<this is not XML”. This is something you do have to escape
before you can include it in XML. Which I bet most people blindly
ignore. Just like quite a few people neglect escaping the values they
include in their rhtml templates. The examples in “Agile Web D.
with Rails” seem to use h() quite randomly.

BTW, in this case there’s no, repeat no, ActiveRecord involved. At times
you may want to create some XML that’s, horrors, not based on a model
inheriting from ActiveRecord. Or even, any model at all.

Anyway, the task is solved, thanks to finding the misnamed (not a big
surprise) function called from xml-simple. I bet it would not be
considered correct by the purists as it doesn’t involve three additional
files.

Jenda
P.S.: My intentional misspellings aside … there is no such word as
“seperation”. I’ve seen it quite a few times already and really wonder
why do people tend to write separation this way.

“sdf<sorry<this is not XML”. This is something you do have to escape
before you can include it in XML. Which I bet most people blindly
ignore. Just like quite a few people neglect escaping the values they
include in their rhtml templates. The examples in “Agile Web D.
with Rails” seem to use h() quite randomly.

BTW, in this case there’s no, repeat no, ActiveRecord involved. At times
you may want to create some XML that’s, horrors, not based on a model
inheriting from ActiveRecord. Or even, any model at all.

Anyway, the task is solved, thanks to finding the misnamed (not a big
surprise) function called from xml-simple. I bet it would not be
considered correct by the purists as it doesn’t involve three additional
files.

Jenda
P.S.: My intentional misspellings aside … there is no such word as
“seperation”. I’ve seen it quite a few times already and really wonder
why do people tend to write separation this way.

I know what is needed to do and what is not. But thanks for showing me
anyways. As for my example with ActiveRecord: it just illustrated whats
the functions intention.

String#to_xml is nonsense, because a String can be everything from xml
to anything else. The process of escaping a String a kind of
normalization, so the method REXML::Text::normalize() perfectly
describes the context.

By the way, AFAIK Builder automatically escapes Strings that are used as
text.

Greetings
Skade

P.S.: Ever considered that there are non-native speakers posting on this
list? I wish to see your german and french spelling.

Jenda K. wrote:

Oops, sorry.

require ‘rexml/document’
REXML::Text::normalize(…)

lovely. normalize(). Sure. Why not wrooblify()? When it comes to names
the Ruby folk is really inventive.

Uh, the Ruby folks didn’t come up with ‘normalize’, the w3c did:

http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-normalize

It’s always seemed like a perfectly descriptive term to me.

b

Florian G. wrote:

By the way, AFAIK Builder automatically escapes Strings that are used as
text.

And as of version 2.0 even the strings that are used as attributes. But
everything is nice, clean and automatic. Yeah, sure.

Greetings
Skade

P.S.: Ever considered that there are non-native speakers posting on this
list? I wish to see your german and french spelling.

Then I wish to see your czech spelling :stuck_out_tongue:

Jenda
BTW, to separate is separieren in german and séparer in french. No “e”
after the “p” either.

On 4/12/07, Jenda K. [email protected] wrote:

Skade

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

Yeah, we really don’t appreciate this “high and mighty” attitude. If you
have a problem using Rails or questions about Rails, please state them.
The
fact that you’re complaining about “normalize”, which is a perfectly
valid
and oft-used method name all through Computer Science tells me that
you’re
just looking for something to complain about. In that case, we don’t
want
you around here. So either drop the attitude or just stop posting here
altogether. Thanks.

Jason

Jenda K. wrote:

“sdf<sorry<this is not XML”. This is something you do have to escape
before you can include it in XML. Which I bet most people blindly
ignore. Just like quite a few people neglect escaping the values they
include in their rhtml templates. The examples in “Agile Web D.
with Rails” seem to use h() quite randomly.

According to the builder docs:

“The special XML characters <, >, and & are converted to <, > and
& automatically. Use the << operation to insert text without
modification.”

Now, seems like there are a few more chars that should be escaped… but
those are the critical ones. Also, that h() method does the same thing.

BTW, in this case there’s no, repeat no, ActiveRecord involved. At times
you may want to create some XML that’s, horrors, not based on a model
inheriting from ActiveRecord. Or even, any model at all.

The to_xml stuff is added in rails… oriented towards serializing AR
objects. If you’re not doing AR, you probably need to just do your own
xml building. Builder is the easiest xml building library I’ve ever
seen. Rexml is almost as easy and way more powerful.

Anyway, the task is solved, thanks to finding the misnamed (not a big
surprise) function called from xml-simple. I bet it would not be
considered correct by the purists as it doesn’t involve three additional
files.

Glad you figured it out. XML purists would probably recommend learning
something about the DOM before attacking people for method names that
they did not choose.

b

BTW, in this case there’s no, repeat no, ActiveRecord involved. At times
you may want to create some XML that’s, horrors, not based on a model
inheriting from ActiveRecord. Or even, any model at all.

If you get this worked up about finding one method in the
documentation and not understanding the purpose of another, I would
recommend another occupation than programming. You’re bound to run
into much bigger issues than these over the course of a career in this
profession. It sounds like it’d be best to get out before your soul
surrenders to such rage.

P.S.: For anyone in doubt, this is not acceptable behavior on the
mailing list. If you’re looking for help, please filter your anger out
before posting.