Skip to content

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

@ronaldtse

Description

@ronaldtse

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions