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

lutaml-model broken support of namespace-less child elements under a namespaced parent #7

Open
ronaldtse opened this issue Nov 11, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@ronaldtse
Copy link
Member

The default Termium XML output looks like this:

<ns2:termium_extract xmlns:ns2="http://termium.tpsgc-pwgsc.gc.ca/schemas/2012/06/Termium"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" language="EN"
  xsi:schemaLocation="http://termium.tpsgc-pwgsc.gc.ca/schemas/2012/06/Termium http://termium.tpsgc-pwgsc.gc.ca/schemas/2012/06/Termium.xsd">
  <extractLanguage language="EN" order="0" />
  <extractLanguage language="FR" order="1" />
...

Here, the termium_extract element has a namespace marked as ns2, but its children have no namespaces.

Technically, it should be parsed like this:

module Termium
  # For <extract>
  class Extract < Lutaml::Model::Serializable
    attribute :language, :string
    attribute :extract_language, ExtractLanguage, collection: true
    attribute :core, Core, collection: true

    xml do
      root "termium_extract"
      namespace "http://termium.tpsgc-pwgsc.gc.ca/schemas/2012/06/Termium", "ns2"

      map_attribute "language", to: :language, namespace: nil
      map_element "extractLanguage", to: :extract_language, namespace: nil
      map_element "core", to: :core, namespace: nil
    end

  end
end

However, this fails because it treats all its children with the same ns2 namespace. Since the children elements have no namespace, they are all ignored.

Instead, this would work:

module Termium
  class Extract < Lutaml::Model::Serializable
    attribute :language, :string
    attribute :extract_language, ExtractLanguage, collection: true
    attribute :core, Core, collection: true

    xml do
      root "termium_extract"

      map_attribute "language", to: :language
      map_element "extractLanguage", to: :extract_language
      map_element "core", to: :core
    end
  end
end

Which is treating the element itself with no namespace, and the children have no namespace. This generates proper XML.

This is a bug in lutaml-model.

This can be found reproducible in the PR.

@ronaldtse
Copy link
Member Author

This is demonstrated in #9.

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

2 participants