Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails support #94

Closed
espen opened this issue May 30, 2014 · 16 comments
Closed

Rails support #94

espen opened this issue May 30, 2014 · 16 comments

Comments

@espen
Copy link

espen commented May 30, 2014

Any plans on adding support to be used with ActiveSupport?

@ohler55
Copy link
Owner

ohler55 commented May 30, 2014

This is the first interest I've had in XML and ActiveSupport. Most people use JSON. If you are interested and would like to work with me on it I would not mind looking more deeply at it.

@espen
Copy link
Author

espen commented May 30, 2014

Yeah all the cool Rails kids are using JSON (myself included). I have some API partners who are .net shops and they consume XML from my API though. I suspect that is the case for some others as well, particularity apps that are more geared towards enterprise usage. Unfortunately the Rails community doesn't put that much love into it (example: rails-api/active_model_serializers#448)

Here is the nokogiri adapter btw: https://github.com/rails/rails/blob/8dd4aca4850c678f96d0a72098b3a080b51dea44/activesupport/lib/active_support/xml_mini/nokogiri.rb

I just started testing out oj in our Rails app today and see a 10% performance increase (thanks!) with some simple benchmarking. Trying it out in staging now. If I can get a performance increase by switching the XML parser as well that would be great as most of the requests to the app is through the API.

@espen
Copy link
Author

espen commented May 30, 2014

I also had a look at multi_xml which supports ox, perhaps a better solution is for them to add active_support support? Then other gems would benefit too.

@ohler55
Copy link
Owner

ohler55 commented May 30, 2014

I'll look at it more carefully this week.

@dvandersluis
Copy link

Has there been any progress with this? I have some pretty big xml feeds that my Rails app generates that take forever and I'd love to be able to speed them up.

@ohler55
Copy link
Owner

ohler55 commented Mar 30, 2016

It did not seem like something I wanted to tackle at the time. Lets discuss a bit though. You mentioned the nokogiri adapter. Would something like that be what you need but instead for Ox?

@dvandersluis
Copy link

I think I actually misunderstood what this issue was about (I'm not the original poster). What I'd like to do is use Ox with something (or instead of something) like the builder gem to build XML for my Rails app to serve XML. I'm trying to put something together myself, but if you had any ideas I'd appreciate it (assuming this is the correct issue for this discussion).

@ohler55
Copy link
Owner

ohler55 commented Mar 30, 2016

Probably should be a separate discussion. Since its not really an issue but a request for how to make something new lets handle it with email to start with and when we have a better idea what it is we can create an issue.

@mario-amazing
Copy link

Hi @ohler55, first of all, I want to say great thanks for all your work!
Do you have plans to add Ox to rails ActiveSupport::XmlMini?
https://github.com/rails/rails/tree/master/activesupport/lib/active_support/xml_mini

@ohler55
Copy link
Owner

ohler55 commented Sep 26, 2019

If it was something I could do in Ox I would but that change would have to be made to rails itself. I can make an attempt by submitting a PR but with almost 800 outstanding PRs I suspect it will take a very long time for such a PR to be accepted. Maybe I'm being pessimistic though. @mario-amazing would you be interested in testing?

@mario-amazing
Copy link

Sounds interesting, I'll really glad to help you with this PR.
So maybe you can check the possibility to add Ox support to rails like a module?
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/xml_mini.rb#L191

@ohler55
Copy link
Owner

ohler55 commented Sep 30, 2019

Yes, that would be the plan. To start out, can you tell me what the conversion is from Ruby objects to XML is? I'll use that as part of a test suite.

@mario-amazing
Copy link

You can check expected XML formatting from rails acrive_support xml_mini tests. There are many examples)
https://github.com/rails/rails/blob/master/activesupport/test/xml_mini/xml_mini_engine_test.rb

@ohler55
Copy link
Owner

ohler55 commented Oct 1, 2019

That helps some. I'll look for other examples as well.

@mario-amazing
Copy link

Do you want something like that?

Xml ->

<recipe type="dessert">
    <recipename cuisine="american" servings="1">Ice Cream Sundae</recipename>
    <ingredlist>
        <listitem>
            <quantity units="cups">0.5</quantity>
            <itemdescription>vanilla ice cream</itemdescription>
        </listitem>
        <listitem>
            <quantity units="tablespoons">3</quantity>
            <itemdescription>chocolate syrup or chocolate fudge</itemdescription>
        </listitem>
        <listitem>
            <quantity units="tablespoons">1</quantity>
            <itemdescription>nuts</itemdescription>
        </listitem>
        <listitem>
            <quantity units="each">1</quantity>
            <itemdescription>cherry</itemdescription>
        </listitem>
    </ingredlist>
    <utensils>
        <listitem>
            <quantity units="each">1</quantity>
            <utensilname>bowl</utensilname>
        </listitem>
        <listitem>
            <quantity units="each">1</quantity>
            <utensilname>spoons</utensilname>
        </listitem>
        <listitem>
            <quantity units="each">1</quantity>
            <utensilname>ice cream scoop</utensilname>
        </listitem>
    </utensils>
    <directions>
        <step>Using ice cream scoop, place vanilla ice cream into bowl.</step>
        <step>Drizzle chocolate syrup or chocolate fudge over the ice cream.</step>
        <step>Sprinkle nuts over the mound of chocolate and ice cream.</step>
        <step>Place cherry on top of mound with stem pointing upward.</step>
        <step>Serve.</step>
    </directions>
    <variations>
        <option>Replace nuts with raisins.</option>
        <option>Use chocolate ice cream instead of vanilla ice cream.</option>
    </variations>
    <preptime>5 minutes</preptime>
</recipe>

Rails expected Hash ->

{"recipe"=>
  {"type"=>"dessert",
   "recipename"=>{"cuisine"=>"american", "servings"=>"1", "__content__"=>"Ice Cream Sundae"},
   "ingredlist"=>
    {"listitem"=>
      [{"quantity"=>{"units"=>"cups", "__content__"=>"0.5"}, "itemdescription"=>{"__content__"=>"vanilla ice cream"}},
       {"quantity"=>{"units"=>"tablespoons", "__content__"=>"3"}, "itemdescription"=>{"__content__"=>"chocolate syrup or chocolate fudge"}},
       {"quantity"=>{"units"=>"tablespoons", "__content__"=>"1"}, "itemdescription"=>{"__content__"=>"nuts"}},
       {"quantity"=>{"units"=>"each", "__content__"=>"1"}, "itemdescription"=>{"__content__"=>"cherry"}}]},
   "utensils"=>
    {"listitem"=>
      [{"quantity"=>{"units"=>"each", "__content__"=>"1"}, "utensilname"=>{"__content__"=>"bowl"}},
       {"quantity"=>{"units"=>"each", "__content__"=>"1"}, "utensilname"=>{"__content__"=>"spoons"}},
       {"quantity"=>{"units"=>"each", "__content__"=>"1"}, "utensilname"=>{"__content__"=>"ice cream scoop"}}]},
   "directions"=>
    {"step"=>
      [{"__content__"=>"Using ice cream scoop, place vanilla ice cream into bowl."},
       {"__content__"=>"Drizzle chocolate syrup or chocolate fudge over the ice cream."},
       {"__content__"=>"Sprinkle nuts over the mound of chocolate and ice cream."},
       {"__content__"=>"Place cherry on top of mound with stem pointing upward."},
       {"__content__"=>"Serve."}]},
   "variations"=>
    {"option"=>[{"__content__"=>"Replace nuts with raisins."}, {"__content__"=>"Use chocolate ice cream instead of vanilla ice cream."}]},
   "preptime"=>{"__content__"=>"5 minutes"}}}

@ohler55
Copy link
Owner

ohler55 commented Oct 3, 2019

Perfect, thanks. I think it would make sense to add the conversion from XML to Hash to Ox directly and then create a simpler hook into rails.

@ohler55 ohler55 closed this as completed Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants