![]() |
Home Compute Inkscape Contact | ![]() |
|||||
Deleting Objects
#!/usr/bin/env python """ delete.py A simple effect that deletes the selected elements as an example of functional (though likely not optimal) methods of: -extracting ids from the command line arguments -reading SVG document into a DOM tree object -locating and manipulating the selected nodes -serializing the DOM tree into an XML document on STDOUT Reference: http://pyxml.sourceforge.net/topics/howto/section-DOM.html """ import sys, getopt import xml.dom.ext import xml.dom.ext.reader.Sax2 import xml.xpath #collect ids from the arguments opts = getopt.getopt(sys.argv[1:],'',['id=']) ids = [opt[1] for opt in opts[0] if opt[0]=='--id'] #create xml parser reader = xml.dom.ext.reader.Sax2.Reader() #open SVG tempfile stream = open(sys.argv[-1:][0],'r') #create DOM object doc = reader.fromStream(stream) stream.close() #Code to modify the DOM object goes here for id in ids: path = '//*[@id="%s"]' % id for node in xml.xpath.Evaluate(path,doc): node.parentNode.removeChild(node) #serialize DOM object into XML on stdout xml.dom.ext.Print(doc) Files: |
|||||||
![]() |
![]() |
||||||
| Home Compute Inkscape Contact | |||||||