Skip to content

fix: builtins/publish: keep xs+xsi NS in cleanup - #334

Open
vladimir-mencl-eresearch wants to merge 2 commits into
IdentityPython:masterfrom
REANNZ:fix-keep-xs-ns-prefixes
Open

fix: builtins/publish: keep xs+xsi NS in cleanup#334
vladimir-mencl-eresearch wants to merge 2 commits into
IdentityPython:masterfrom
REANNZ:fix-keep-xs-ns-prefixes

Conversation

@vladimir-mencl-eresearch

Copy link
Copy Markdown

Fixes #333

The lxml.etree.cleanup_namespaces function only considers namespaces used in XML Element and Attribute names, but not in attribute values. The xs namespace is used only in values of xsi:type attributes and is thus not considered as used by LXML, and would get removed.

Keep it explicitly to avoid creating invalid metadata.

All Submissions:

  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you added an explanation of what problem you are trying to solve with this PR?
  • Have you added information on what your changes do and why you chose this as your solution?
  • [NotYet] Have you written new tests for your changes?
  • [N/A] Does your submission pass tests?
  • This project follows PEP8 style guide. Have you run your code against the 'flake8' linter?

Fixes IdentityPython#333

The lxml.etree.cleanup_namespaces function only considers namespaces used
in XML Element and Attribute names, but not in attribute values.
The xs namespaces is used only in values of xsi:type attributes
and is thus not considered as used by LXML - and would get removed.

Keep it explicitly to avoid creating invalid metadata.
@vladimir-mencl-eresearch

Copy link
Copy Markdown
Author

FYI @theseal @btmattsson

The namespace cleanup was being ignored for MDQ
per-entity publication - it did nothing when
invoked on element other than the root element.

It would also be resource intensive to clean up
when publishing each individual element.

Clean up instead at the source - and there,
the guard condition is no longer required
(the working document is always XML)
@vladimir-mencl-eresearch

vladimir-mencl-eresearch commented Sep 3, 2026

Copy link
Copy Markdown
Author

Hi,

I have looked into this a bit deeper - I was surprised #333 broke only conventional metadata but not MDQ.

Turns out the namespace cleanup was skipping over MDQ (cleanup_namespaces does nothing when invoked on an element that is not the root element).

So I have moved the namespace cleanup to where the document is created - that solves it also for MDQ files (and I have kept keep_ns_prefixes that fix for #333).

Please let me know what you think. If you'd rather just fix #333 only with no other changes, the first commit will do it. The second commit makes NS cleanup apply also to MDQ files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: cleanup_namespaces removes also xs + xsi prefixes

1 participant