This project is archived and is in readonly mode.

#2723 ✓committed
blythe

to_xml generates invalid xml with namespaced ActiveRecord

Reported by blythe | May 26th, 2009 @ 11:48 PM | in 2.3.4

When using an ActiveRecord object with a namespace, the generated xml is not valid.

MyApplication::Business::Project would generate
<my-application/business/project> which unescaped isn't valid xml.

When using the :include option, the association name is used but the type is set to the full project name.

In the patch I demodulized the names (which removes the type field), but I am unsure if the type should also be set to the full ruby class name.

Without patch:
<?xml version="1.0" encoding="UTF-8"?>
<my-application/business/project>
1 Active Record

<developer type="MyApplication::Business::Developer">
  <access-level type="NilClass">1</access-level>
  <created-at type="datetime" nil="true"></created-at>
  <developer-id type="NilClass">1</developer-id>
  <id type="integer">1</id>
  <joined-on type="NilClass">2004-10-10</joined-on>
  <name>David</name>
  <project-id type="NilClass">1</project-id>
  <salary type="integer">80000</salary>
  <updated-at type="datetime" nil="true"></updated-at>
</developer>

With patch:

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <id type="integer">1</id>
  <name>Active Record</name>
  <developers type="array">
    <developer>
      <access-level type="NilClass">1</access-level>
      <created-at type="datetime" nil="true"></created-at>
      <developer-id type="NilClass">1</developer-id>
      <id type="integer">1</id>
      <joined-on type="NilClass">2004-10-10</joined-on>
      <name>David</name>
      <project-id type="NilClass">1</project-id>
      <salary type="integer">80000</salary>
      <updated-at type="datetime" nil="true"></updated-at>
    </developer>
    <developer>

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages