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

Problematic xmlns:ns0 with write_xml #246

Open
alexreg opened this issue Feb 16, 2024 · 1 comment
Open

Problematic xmlns:ns0 with write_xml #246

alexreg opened this issue Feb 16, 2024 · 1 comment

Comments

@alexreg
Copy link

alexreg commented Feb 16, 2024

Take an SVG like the following.

<svg xmlns:ns0="http://www.w3.org/1999/xlink" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events">
    ...
</svg>

If I then load and write this SVG back to a file, as follows.

svg = SVG.parse("input.svg")
svg.write_xml("output.svg")

Then I get something like this.

<svg xmlns:ns0="http://www.w3.org/1999/xlink" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events">
    ...
</svg>

This is invalid XML, since the same namespace is defined with two different names (ns0 and xlink), and causes problems with some other programs that read SVGs.

@saardrimer
Copy link

Have a look at:

https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.register_namespace

which will register the namespace and quite possibly resolve your issue.

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

No branches or pull requests

2 participants