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

Jenda Krynicky 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 Development with Rails" seem to use h() quite randomly.

According to the builder docs:

"The special XML characters <, >, and & are converted to &lt;, &gt; and &amp; 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.