Strip out all namespace declarations, tags and attributes from SVG file with Python/lxml
问题 I have this script for cleaning up SVG files with Python and lxml. It removes invisible elements and tries to solve a few selected namespace issues: from lxml import etree path = '/image.svg' svg_xml = open(path, 'r').read() # resolve problematic namespace issues # remove specific and undefined Illustrator tags if '<i:pgf></i:pgf>' in svg_xml: svg_xml = svg_xml.replace('<i:pgf></i:pgf>', '') # make sure the xmlns:xlink URL is correct if 'xmlns:xlink' in svg_xml: parts = svg_xml.split('xmlns