0

I am using Python ElementTree 3.3 with Python 3.9 on Win10.

I am working on a project for which I created some custom xml-attributes to add to svg files to modify them with an external script. These attributes, of course, are not part of the standard xml 'accepted' attributes. Now I thought that did not matter since I would be handling them myself and ElementTree simply has to parse the attributes at the points I want them, however I get the Error message:

ValueError: Invalid attribute name 'this:custom-tag'

The line of code that invokes the error is the following:

e.set('this:custom-tag' , 'transform({{' +  'var ' + '}},' + rPoint1 + ',' + rPoint2 + ')')

Is there a way for me to expand the list of accepted attributes?

1 Answers1

0

So it works just as the thread @mzjn sent says. I had to add a new namespace, define the new command and then set that command. It looks like this:

ET.register_namespace('ns-name-xml', namespace)

and then in my case I iterated over the elements of the root of the xml-file:

for e in outputRoot:
        if e.get('id') == selectedRow:
            e.set(ET.QName(namespace,'your-command') , 'some-value')