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

mixed: true in xml mapping is not working as expected #97

Open
suleman-uzair opened this issue Oct 3, 2024 · 2 comments
Open

mixed: true in xml mapping is not working as expected #97

suleman-uzair opened this issue Oct 3, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@suleman-uzair
Copy link

When I try to parse the following XML:

<math>
  <mrow>
     <mi>x</mi>
     <mo>+</mo>
     <mi>y</mi>
  </mrow>
</math>

Using the following code:

require 'lutaml/model'
Lutaml::Model::Config.configure do |config|
  require 'lutaml/model/xml_adapter/nokogiri_adapter'
  config.xml_adapter = Lutaml::Model::XmlAdapter::NokogiriAdapter
end

class Mi < Lutaml::Model::Serializable
  attribute :value, :string

  xml do
    root "mi"

    map_content to: :value
  end
end

class Mo < Lutaml::Model::Serializable
  attribute :value, :string

  xml do
    root "mo"

    map_content to: :value
  end
end

class Mrow < Lutaml::Model::Serializable
  attribute :mi, Mi
  attribute :mo, Mo

  xml do
    root "mrow", mixed: true

    map_element :mi, to: :mi
    map_element :mo, to: :mo
  end
end

class Mathml < Lutaml::Model::Serializable
  attribute :mrow, Mrow, collection: true

  xml do
    root "math", mixed: true

    map_element :mrow, to: :mrow
  end
end


Mathml.from_xml("<math><mrow><mi>x</mi><mo>+</mo><mi>y</mi></mrow></math>")
> #<Mathml:0x0000000104879308
@element_order=["mrow"],
@mrow=
 [#<Mrow:0x0000000104872670
   @element_order=["mi", "mo", "mi"],
   @mi=
    [#<Mi:0x000000010485d568 @element_order=["text"], @ordered=nil, @validate_on_set=false, @value="x">,
     #<Mi:0x00000001049589e0 @element_order=["text"], @ordered=nil, @validate_on_set=false, @value="y">],
   @mo=#<Mo:0x00000001047fa0d0 @element_order=["text"], @ordered=false, @validate_on_set=false, @value="+">,
   @ordered=true,
   @validate_on_set=false>],
@ordered=true,
@validate_on_set=false>

How can I get the output formula as mi(x), mo(+), mi(y) and not mi(x), mi(y), mo(+)? is there anything I can do using mixed option?

@ronaldtse ronaldtse added the bug Something isn't working label Oct 4, 2024
@ronaldtse
Copy link
Contributor

@suleman-uzair is this addressed?

@suleman-uzair
Copy link
Author

is this addressed?

@ronaldtse, No, it’s not addressed yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants