Fix keep xs ns prefixes - #335
Conversation
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 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. Co-authored-by: Johan Wassberg <jocar@sunet.se>
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) Co-authored-by: Johan Wassberg <jocar@sunet.se>
Instead of a hardcorded list of known Qname defines
|
@vladimir-mencl-eresearch Can you try this branch out before we do a merge? |
|
Thanks @btmattsson - good catch, I was taking a short-cut here for commonly used namespace prefixes - but it's not guaranteed that exactly these prefixes would be used. (And some tooling could possibly normalise/rename prefixes...) Thanks for this extra work @theseal - and sorry, I missed signing my commits (will remember for this project for the future) - and I should have allowed you access to the branch (will remember as well). I've just tested this in my (DEV) env and it works exactly as expected (and also supports the case when the XML schema namespaces are mapped to a different prefix). PS: Your approach is even more generic, supporting also other namespace-scoped attribute values. And is the best we can do without parsing/interpreting the full schema to see which attributes actually declares their values as using namespaces (declaring its type as Thumbs-up from me to merge this. |
Both should be found by qname_prefixes() if they are in use
|
Thumbs up for the latest change - yes, if we are searching for qname values, we no longer need to explicitly whitelist |
|
Looks good |
@vladimir-mencl-eresearch commits where unsigned and I was not allowed to write in the incoming branch so had to do this branch dance. 🤷♂️
Also added test to check for the "default" NSes.
Closes #333 and #334