Transmitting raw data vs. tree-structured data

Hi, I’m trying to decide using one of two approaches getting
tree-structured data to users.

approach #1:
build the tree from raw data in rails model code, then transfer it via
AJAX in XML

approach #2:
transfer all raw data in XML form first, then use javascript to build
the tree.

The problem with approach #1 is that I’m currently stuck doing it.
Building the tree in model code is easy; but I’m having all sort of
problems transferring it. (I can’t use hash.to_xml directly since each
key is an object, and using object.to_xml while building to tree results
in incorrect rendering)

The problem with approach #2 is I don’t know if javascript is power
enough to handle “building a tree from xml, preferably using a hash that
can have associative arrays as keys”, which is why I want to ask around
and post on this forum.

I’m new to both Rails and javascript.

Anyone has any ideas?

Max Y. wrote:

Anyone has any ideas?

Use JSON.

On 2010-06-16 10:52:54 -0700, Brian C. said:

Max Y. wrote:

Anyone has any ideas?

Use JSON.

Use XML or JSON or any other data format (JSON obviously works very
well with javascript), but don’t let your data format design suffer
because to_xml doesn’t get the rendering right. Use Builder or some
other means.

Thank you both for the replies. I ended up mandating all AJAX data
transfer to use JSON format, and it works very well. Additionally, it
turned out very easy to rewrite the stuff and add custom to_json methods
in rails.