Skip to content

Element nesting depth ignored #74

@felixbuenemann

Description

@felixbuenemann

I have the following case:

<root>
  <foo id="1">
    <bar>
      <meta>
        <value id="a"/>
        <value id="b"/>
      </meta>
    </bar>
    <meta>
      <value id="x"/>
      <value id="y"/>
    </meta>
  </foo>
  <foo id="2">
    <meta>
      <value id="z"/>
    </meta>
  </foo>
</root>

And the following mapping:

class Root
  include SAXMachine
  elements :foo, as: :children, class: Foo
end

class Meta
  include SAXMachine
  elements :values, as: :values, class: String
end

class Foo
  include SAXMachine
  element :meta, class: Meta
end

Now if I get metaof foo with id 1, I get the meta node of bar instead of the meta node of foo.

How do I solve this?

Maybe it would be great to have a depth constraint, so I could define something like:

class Foo
  include SAXMachine
  element :meta, class: Meta, depth: 1
  element :other, class: Other, depth: ->(depth) { depth > 2 && depth < 5 }
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions