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

The method .from_xml does not work as expected #147

Closed
kwkwan opened this issue Nov 4, 2024 · 1 comment · Fixed by #148
Closed

The method .from_xml does not work as expected #147

kwkwan opened this issue Nov 4, 2024 · 1 comment · Fixed by #148
Assignees
Labels
bug Something isn't working

Comments

@kwkwan
Copy link
Contributor

kwkwan commented Nov 4, 2024

Assume I have an xmi file:

test = <<XMI
<?xml version="1.0" encoding="windows-1252"?>
<xmi:XMI xmlns:uml="http://www.omg.org/spec/UML/20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:umldi="http://www.omg.org/spec/UML/20131001/UMLDI" xmlns:dc="http://www.omg.org/spec/UML/20131001/UMLDC" xmlns:thecustomprofile="http://www.sparxsystems.com/profiles/thecustomprofile/1.0">
  <xmi:Documentation exporter="Enterprise Architect" exporterVersion="6.5"/>
  <uml:Model xmi:type="uml:Model" name="EA_Model">
    <packagedElement xmi:type="uml:Package" xmi:id="EAPK_C799E047_A10F_4203_9E22_9C47183CED98" name="requirement type class diagram">
    </packagedElement>
  </uml:Model>
</xmi:XMI>
XMI

and I have defined classess like:

module Xmi
  module Uml
    class PackagedElement < Lutaml::Model::Serializable
      attribute :type, :string
      attribute :id, :string
      attribute :name, :string
      attribute :supplier, :string
      attribute :client, :string
      attribute :packaged_element, PackagedElement, collection: true

      xml do
        root "packagedElement"

        map_attribute "type", to: :type, namespace: "http://www.omg.org/spec/XMI/20131001", prefix: "xmi"
        map_attribute "id", to: :id, namespace: "http://www.omg.org/spec/XMI/20131001", prefix: "xmi"
        map_attribute "name", to: :name
        map_attribute "supplier", to: :supplier
        map_attribute "client", to: :client
        map_element "packagedElement", to: :packaged_element
      end
    end

    class UmlModel < Lutaml::Model::Serializable
      attribute :type, :string
      attribute :name, :string
      attribute :packaged_element, PackagedElement, collection: true

      xml do
        root "Model"
        namespace "http://www.omg.org/spec/UML/20131001", "uml"

        map_attribute "type", to: :type, namespace: "http://www.omg.org/spec/XMI/20131001", prefix: "xmi"
        map_attribute "name", to: :name

        map_element "packagedElement", to: :packaged_element, namespace: nil, prefix: nil
      end
    end
  end
end


module Xmi
  class Root < Lutaml::Model::Serializable
    attribute :id, :string
    attribute :label, :string
    attribute :uuid, :string
    attribute :href, :string
    attribute :idref, :string
    attribute :type, :string
    attribute :model, Uml::UmlModel

    xml do
      root "XMI"
      namespace "http://www.omg.org/spec/XMI/20131001", "xmi"

      map_attribute "id", to: :id
      map_attribute "label", to: :label
      map_attribute "uuid", to: :uuid
      map_attribute "href", to: :href, namespace: nil, prefix: nil
      map_attribute "idref", to: :idref
      map_attribute "type", to: :type

      map_element "Model", to: :model,
                           namespace: "http://www.omg.org/spec/UML/20131001",
                           prefix: "uml"
    end
  end
end

module Xmi
  module Sparx
    class SparxRoot < Root
      attribute :id, :string
    
      xml do
        root "XMI"
        namespace "http://www.omg.org/spec/XMI/20131001", "xmi"

        map_attribute "id", to: :id
      end
    end
  end
end

When I run:

require "lutaml/model"
require "nokogiri"
require "lutaml/model/xml_adapter/nokogiri_adapter"


Lutaml::Model::Config.configure do |config|
  config.xml_adapter = Lutaml::Model::XmlAdapter::NokogiriAdapter
end

m = Xmi::Sparx::SparxRoot.from_xml(test)

The packaged_element does NOT parsed as expected:

b(main):276:0> m.model
=> 
#<Xmi::Uml::UmlModel:0x0000000104d2c2d8                                            
 @element_order=["text", "packagedElement", "text"],                               
 @mixed=false,                                                                     
 @name="EA_Model",                                                                 
 @ordered=nil,                                                                     
 @packaged_element=[],                                                             
 @type="uml:Model",                                                                
 @using_default={:type=>false, :name=>false, :packaged_element=>true}>   
@ronaldtse
Copy link
Contributor

@kwkwan can you please help check (and close) if this issue is now resolved? The latest version 0.3.22 is released. Thanks!

@kwkwan kwkwan closed this as completed Nov 5, 2024
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

Successfully merging a pull request may close this issue.

3 participants