avoid xml root for children #240

Open
Raven24 opened this Issue May 13, 2012 · 8 comments

Comments

Projects
None yet
3 participants
@Raven24

Raven24 commented May 13, 2012

Hi!

Maybe I just missed it, but is there an option for generating child objects directly inside the parent (without an intermediate root node)? If not, please add one ;)

What I get currently:

<post>
  ...

  <comments>
    <comment>
    ...
    </comment>
    <comment>
    ...
    </comment>
  </comments>
</post>

What I (very desperately) need:

<post>
  ...

  <comment>
    ...
  </comment>
  <comment>
    ...
  </comment>
</post>

I tried pretty much every combination of node and child and even had a quite pleasant read of your source in search for such an option, but I couldn't find it.

@databyte

This comment has been minimized.

Show comment Hide comment
@databyte

databyte May 16, 2012

Collaborator

Can you give an example or two of the templates you've tried?

Does this not work?

child :comments do
  attributes :id, :title
end

# or even
child :comments => :comments do
  attributes :id, :title
end
Collaborator

databyte commented May 16, 2012

Can you give an example or two of the templates you've tried?

Does this not work?

child :comments do
  attributes :id, :title
end

# or even
child :comments => :comments do
  attributes :id, :title
end
@Raven24

This comment has been minimized.

Show comment Hide comment
@Raven24

Raven24 May 16, 2012

they all produce a root node for the children...
I have config.include_xml_root = false in the config

object @something                 |  <something>
                                  |    <text>...</text><handle>...</handle>
attributes :text, :handle         |    <comments>
                                  |      <comment>...</comment>
child :comments do                |      <comment>...</comment>
  extends "comments/show"         |    </comments>
end                               |  </something>
object @something                 |  <something>
                                  |    <text>...</text><handle>...</handle>
attributes :text, :handle         |    <comments>
                                  |      <comment>...</comment>
child :comments => :comments do   |      <comment>...</comment>
  extends "comments/show"         |    </comments>
end                               |  </something>
object @something                 |  <something>
                                  |    <text>...</text><handle>...</handle>
attributes :text, :handle         |    <comments>
                                  |      <comment>...</comment>
node :comments => do |something|  |      <comment>...</comment>
  something.comments.map { |cmmt| |    </comments>
    { :text => cmmt.text }        |  </something>
  }                               |
end                               |

or produce nothing of use (no comments at all)

object @something                 |  <something>
                                  |    <text>...</text><handle>...</handle>
attributes :text, :handle         |  </something>
                                  |  
node do |something|               |  
  something.comments.map { |cmmt| |  
    { :text => cmmt.text }        |  
  }                               |
end    

My google searches indicated that this might be a limitation of the to_xml method,
because it doesn't handle arrays very well and it seems therefore xml serialzation isn't bijective.
(also, see this discussion: https://groups.google.com/d/topic/rubyonrails-talk/6El1xNwKhSw/discussion)

I think what I need is the serialization of something like this

:something => {
  :attr1 => "val",
  :attr2 => "val",
  :children => [
    { :attr3=>"val", :attr5=>"val"},
    { :attr4=>"val", :attr6=>"val"},
  ]
}

only with the array not using the hash key as root node but directly inserting them into the parent xml...
to become

<something>
  <attr1>val</attr1>
  <attr2>val</attr2>
  <child><attr3>val</attr3><attr5>val</attr5></child>
  <child><attr4>val</attr4><attr6>val</attr6></child>
</something>

Raven24 commented May 16, 2012

they all produce a root node for the children...
I have config.include_xml_root = false in the config

object @something                 |  <something>
                                  |    <text>...</text><handle>...</handle>
attributes :text, :handle         |    <comments>
                                  |      <comment>...</comment>
child :comments do                |      <comment>...</comment>
  extends "comments/show"         |    </comments>
end                               |  </something>
object @something                 |  <something>
                                  |    <text>...</text><handle>...</handle>
attributes :text, :handle         |    <comments>
                                  |      <comment>...</comment>
child :comments => :comments do   |      <comment>...</comment>
  extends "comments/show"         |    </comments>
end                               |  </something>
object @something                 |  <something>
                                  |    <text>...</text><handle>...</handle>
attributes :text, :handle         |    <comments>
                                  |      <comment>...</comment>
node :comments => do |something|  |      <comment>...</comment>
  something.comments.map { |cmmt| |    </comments>
    { :text => cmmt.text }        |  </something>
  }                               |
end                               |

or produce nothing of use (no comments at all)

object @something                 |  <something>
                                  |    <text>...</text><handle>...</handle>
attributes :text, :handle         |  </something>
                                  |  
node do |something|               |  
  something.comments.map { |cmmt| |  
    { :text => cmmt.text }        |  
  }                               |
end    

My google searches indicated that this might be a limitation of the to_xml method,
because it doesn't handle arrays very well and it seems therefore xml serialzation isn't bijective.
(also, see this discussion: https://groups.google.com/d/topic/rubyonrails-talk/6El1xNwKhSw/discussion)

I think what I need is the serialization of something like this

:something => {
  :attr1 => "val",
  :attr2 => "val",
  :children => [
    { :attr3=>"val", :attr5=>"val"},
    { :attr4=>"val", :attr6=>"val"},
  ]
}

only with the array not using the hash key as root node but directly inserting them into the parent xml...
to become

<something>
  <attr1>val</attr1>
  <attr2>val</attr2>
  <child><attr3>val</attr3><attr5>val</attr5></child>
  <child><attr4>val</attr4><attr6>val</attr6></child>
</something>
@databyte

This comment has been minimized.

Show comment Hide comment
@databyte

databyte May 17, 2012

Collaborator

Yeah, what you want is child_root's to be excluded. The use of include_xml_root is for the top level root (afaik).

This is currently being discussed here in Issue #178

We need to get our asses back into gear on that redesign... @nesquena - how busy is your weekend? 😁 😪

Collaborator

databyte commented May 17, 2012

Yeah, what you want is child_root's to be excluded. The use of include_xml_root is for the top level root (afaik).

This is currently being discussed here in Issue #178

We need to get our asses back into gear on that redesign... @nesquena - how busy is your weekend? 😁 😪

@nesquena

This comment has been minimized.

Show comment Hide comment
@nesquena

nesquena May 17, 2012

Owner

@databyte Thanks for the reminder, should probably merge #178 this weekend...

Owner

nesquena commented May 17, 2012

@databyte Thanks for the reminder, should probably merge #178 this weekend...

@databyte

This comment has been minimized.

Show comment Hide comment
@databyte

databyte May 17, 2012

Collaborator

Yeah, I think caching had to be decided on (probably as an option on the collection/object method) but it was close. You knocked most of it out quickly.

Collaborator

databyte commented May 17, 2012

Yeah, I think caching had to be decided on (probably as an option on the collection/object method) but it was close. You knocked most of it out quickly.

@nesquena

This comment has been minimized.

Show comment Hide comment
@nesquena

nesquena May 17, 2012

Owner

Yeah I forget where I left it but I do remember it more or less worked. If we can fix the caching issues, then maybe we can get it in a usable state this weekend.

Owner

nesquena commented May 17, 2012

Yeah I forget where I left it but I do remember it more or less worked. If we can fix the caching issues, then maybe we can get it in a usable state this weekend.

@Raven24

This comment has been minimized.

Show comment Hide comment
@Raven24

Raven24 May 17, 2012

That would be great! I'd be happy to test it, when you've got something ;)

Raven24 commented May 17, 2012

That would be great! I'd be happy to test it, when you've got something ;)

@databyte

This comment has been minimized.

Show comment Hide comment
@databyte

databyte Jun 5, 2012

Collaborator

I saw @nesquena just merged in the config.include_child_root as an option. Try that out in v0.6.13.

Collaborator

databyte commented Jun 5, 2012

I saw @nesquena just merged in the config.include_child_root as an option. Try that out in v0.6.13.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment