Transform a DOM node into new node and copy selected attributes. Creates a new DOM node with tag name 'newTag' for document 'doc' and copies selected attributes from an existing 'node' as provided in 'attrDict'. The source 'node' can be None. Attribute values will be converted to st
(doc, newTag, node=None, **attrDict)
| 62 | return P |
| 63 | |
| 64 | def transformNode(doc, newTag, node=None, **attrDict): |
| 65 | """Transform a DOM node into new node and copy selected attributes. |
| 66 | |
| 67 | Creates a new DOM node with tag name 'newTag' for document 'doc' |
| 68 | and copies selected attributes from an existing 'node' as provided |
| 69 | in 'attrDict'. The source 'node' can be None. Attribute values will |
| 70 | be converted to strings. |
| 71 | |
| 72 | E.g. |
| 73 | |
| 74 | n = transformNode(doc, "node1", x="0", y="1") |
| 75 | -> DOM node for <node1 x="0" y="1"/> |
| 76 | |
| 77 | n = transformNode(doc, "node1", x=0, y=1+1) |
| 78 | -> DOM node for <node1 x="0" y="2"/> |
| 79 | |
| 80 | n = transformNode(doc, "node1", node0, x="x0", y="x0", zoo=bar()) |
| 81 | -> DOM node for <node1 x="[node0.x0]" y="[node0.y0]" zoo="[bar()]"/> |
| 82 | """ |
| 83 | |
| 84 | newNode = doc.createElement(newTag) |
| 85 | for newAttr, attr in attrDict.items(): |
| 86 | sattr = str(attr) |
| 87 | if not node: |
| 88 | newNode.setAttribute(newAttr, sattr) |
| 89 | else: |
| 90 | attrVal = node.getAttribute(sattr) |
| 91 | newNode.setAttribute(newAttr, attrVal or sattr) |
| 92 | |
| 93 | return newNode |
| 94 | |
| 95 | ### classes ### |
| 96 | class SVGCanvas: |
no outgoing calls
no test coverage detected