From d323059b9db610ac0dda23475729cde5f5c0a619 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Thu, 12 Apr 2018 20:05:01 -0400 Subject: [PATCH] always add inkstitch XML namespace --- inkstitch/extensions.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/inkstitch/extensions.py b/inkstitch/extensions.py index 7795abb8f..d48fcc8c7 100644 --- a/inkstitch/extensions.py +++ b/inkstitch/extensions.py @@ -101,3 +101,24 @@ class InkstitchExtension(inkex.Effect): patches.extend(element.embroider(last_patch)) return patches + + def parse(self): + """Override inkex.Effect to add Ink/Stitch xml namespace""" + + # SVG parsers don't actually look for anything at this URL. They just + # care that it's unique. That defines a "namespace" of element and + # attribute names to disambiguate conflicts with element and + # attribute names other XML namespaces. + # + # Updating inkex.NSS here allows us to pass 'inkstitch' into + # inkex.addNS(). + inkex.NSS.update('inkstitch', 'http://inkstitch.org/namespace') + + # call the superclass's method first + inkex.Effect.parse(self) + + # This is the only way I could find to add a namespace to an existing + # element tree at the top without getting ugly prefixes like "ns0". + inkex.etree.cleanup_namespaces(inkex.document, + top_nsmap=inkex.NSS, + keep_ns_prefixes=inkex.NSS.keys())