| 1617 | | # Turns this record into XML |
|---|
| | 1617 | # Builds an XML document to represent the model. Some configuration is |
|---|
| | 1618 | # availble through +options+, however more complicated cases should use |
|---|
| | 1619 | # Builder. |
|---|
| | 1620 | # |
|---|
| | 1621 | # By default the generated XML document will include the processing |
|---|
| | 1622 | # instruction and all object's attributes. For example: |
|---|
| | 1623 | # |
|---|
| | 1624 | # <?xml version="1.0" encoding="UTF-8"?> |
|---|
| | 1625 | # <topic> |
|---|
| | 1626 | # <title>The First Topic</title> |
|---|
| | 1627 | # <author-name>David</author-name> |
|---|
| | 1628 | # <id type="integer">1</id> |
|---|
| | 1629 | # <approved type="boolean">false</approved> |
|---|
| | 1630 | # <replies-count type="integer">0</replies-count> |
|---|
| | 1631 | # <bonus-time type="datetime">2000-01-01T08:28:00+12:00</bonus-time> |
|---|
| | 1632 | # <written-on type="datetime">2003-07-16T09:28:00+1200</written-on> |
|---|
| | 1633 | # <content>Have a nice day</content> |
|---|
| | 1634 | # <author-email-address>david@loudthinking.com</author-email-address> |
|---|
| | 1635 | # <parent-id></parent-id> |
|---|
| | 1636 | # <last-read type="date">2004-04-15</last-read> |
|---|
| | 1637 | # </topic> |
|---|
| | 1638 | # |
|---|
| | 1639 | # This behaviour can be controlled with :skip_attributes and :skip_instruct |
|---|
| | 1640 | # for instance: |
|---|
| | 1641 | # |
|---|
| | 1642 | # topic.to_xml(:skip_instruct => true, :skip_attributes => [ :id, bonus_time, :written_on, replies_count ]) |
|---|
| | 1643 | # |
|---|
| | 1644 | # <topic> |
|---|
| | 1645 | # <title>The First Topic</title> |
|---|
| | 1646 | # <author-name>David</author-name> |
|---|
| | 1647 | # <approved type="boolean">false</approved> |
|---|
| | 1648 | # <content>Have a nice day</content> |
|---|
| | 1649 | # <author-email-address>david@loudthinking.com</author-email-address> |
|---|
| | 1650 | # <parent-id></parent-id> |
|---|
| | 1651 | # <last-read type="date">2004-04-15</last-read> |
|---|
| | 1652 | # </topic> |
|---|
| | 1653 | # |
|---|
| | 1654 | # To include first level associations use :include |
|---|
| | 1655 | # |
|---|
| | 1656 | # firm.to_xml :include => [ :account, :clients ] |
|---|
| | 1657 | # |
|---|
| | 1658 | # <?xml version="1.0" encoding="UTF-8"?> |
|---|
| | 1659 | # <firm> |
|---|
| | 1660 | # <id type="integer">1</id> |
|---|
| | 1661 | # <rating type="integer">1</rating> |
|---|
| | 1662 | # <name>37signals</name> |
|---|
| | 1663 | # <clients> |
|---|
| | 1664 | # <client> |
|---|
| | 1665 | # <rating type="integer">1</rating> |
|---|
| | 1666 | # <name>Summit</name> |
|---|
| | 1667 | # </client> |
|---|
| | 1668 | # <client> |
|---|
| | 1669 | # <rating type="integer">1</rating> |
|---|
| | 1670 | # <name>Microsoft</name> |
|---|
| | 1671 | # </client> |
|---|
| | 1672 | # </clients> |
|---|
| | 1673 | # <account> |
|---|
| | 1674 | # <id type="integer">1</id> |
|---|
| | 1675 | # <credit-limit type="integer">50</credit-limit> |
|---|
| | 1676 | # </account> |
|---|
| | 1677 | # </firm> |
|---|