简体   繁体   中英

java tree class to XML through jRuby on rails

I have a custom Java Tree class (from stanford parser ,) that I am able to work with in JRuby on Rails.

What I am trying to figure out how to do is to output this tree class to XML through rails

The tree class describes a word tree derived from a parsed sentence. Each tree may have multiple child trees depending on the structure

Here is a simple example based off of the sentence "I am a robot":

Tree: Root
-Tree: Sentence
--Tree: Noun
---Tree: I
--Tree: Verb
----Tree: am
--Tree: Noun
---Tree: a
---Tree: robot

One important detail is that I don't need to store any of this in a database, so using ActiveRecord may not be the best choice.

Do you have any ideas about the best approach for this? I have read some ideas in tutorials, but I'm not sure what the best way for my case is, especially since I am very new to rails and don't yet understand 'the rails way'

EDIT:

Option 1: use the builder gem

Option 2: create an (activerecord?) wrapper class in ruby

Option 3: create a special to_xml function (in java?) for this class

Any other ideas?

I created a class in ruby that on initialization imports from the java tree object. I'm still trying to figure out how to structure it best, and I have not written a good to_xml class. though, on further reading, I think I will use JSON instead of xml?

Thanks!

I think the best approach would be to create an ActiveModel class (part of Rails 3.0). You can decorate any object with ActiveModel and you get all the ActionPack goodness without having to be tied to a DB. You get to_xml and to_json for free.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM