It seems that Python's internal XML parser is good enough to do the job.
...except that Ghostscript will sometimes turn out of line images into inline images on its own, possibly if file size is small.