Je manipule des fichiers SVG dans ElementTree. Compte tenu du fichier test.svg
Ajouter un attribut préfixé dans ElementTree
<?xml version='1.0' encoding='utf-8'?>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
</svg>
J'ai essayé de créer un élément avec préfixe spécifique
import xml.etree.ElementTree as ET
ET.register_namespace("", "http://www.w3.org/2000/svg")
tree = ET.parse('test.svg')
tree.getroot().set("xmlns:xlink", "http://www.w3.org/1999/xlink")
link = ET.fromstring('<a xlink:href="http://www.mysite.com/"></a>')
tree.write('worldMap/test_out.svg', encoding = 'utf-8', xml_declaration = True)
mais courir dans une erreur unbound prefix
. J'ai regardé this tutorial mais je n'arrive pas à voir ce qui ne va pas.
Alors ce qui est la question? – enginefree