lutaml / shale

Shale is a Ruby object mapper and serializer for JSON, YAML, TOML, CSV and XML. It allows you to parse JSON, YAML, TOML, CSV and XML data and convert it into Ruby data structures, as well as serialize data structures into JSON, YAML, TOML, CSV or XML.
https://shalerb.org/
MIT License
0 stars 1 forks source link

Support for versioned namespace elements #8

Open ronaldtse opened 2 months ago

ronaldtse commented 2 months ago

From:

Relates to:

Right now in the round-trip task, the <profiles> tag is entirely missing because:

       -    <profiles>
       -      <uml:Profile xmlns:uml="http://www.omg.org/spec/UML/20161101" xmlns:xmi="http://www.omg.org/spec/XMI/20161101" xmi:id="thecustomprofile" nsPrefix="thecustomprofile" name="thecustomprofile" metamodelReference="mmref01">

The <uml:Profile> tag uses:

But the rest of the document uses:

The way to solve this is to only apply the newer namespace on this particular Profile element. This means that all the 'uml' and 'xmi' element inside here need to be a different set of Ruby classes that inherit from the old version (2013).

e.g. uml:Profile contains ownedComment, packageImport, packagedElement etc.

Potential solution:

class Uml2016::OwnedComment < Uml2013::OwnedComment
  xml do
    # ...
    namespace "http://www.omg.org/spec/UML/20161101", "uml"
  end
end

class Uml2016::Profile < Shale::Mapper
  attribute :owned_comment, Uml2016::OwnedComment
  xml do
    root 'Profile'
    namespace "http://www.omg.org/spec/UML/20161101", "uml"
    map_attribute `ownedComment`, to: :owned_comment
  end
end