How to get an XML DOM while offline?

Fredrik Lundh fredrik at pythonware.com
Mon Apr 7 02:52:08 EDT 2008


Stefan Behnel wrote:

>> Is there a simpler way to read the iTunes XML? (It's merely a plist,
>> so the format is much simpler than general XML.)
> 
> Try lxml. Since version 2.0, its parsers will not access the network unless
> you tell it to do so.
> 
> http://codespeak.net/lxml

which makes it true for all ET implementations (the whole idea that 
parsing a file should result in unexpected network access is of course a 
potential security risk and one of a number of utterly stupid design 
decisions in XML).

you'll find plist reading code here, btw:

   http://effbot.org/zone/element-iterparse.htm#incremental-decoding

replace the import with "from xml.etree import cElementTree" if you're 
running 2.5.

(not sure if that one works with lxml, though, but that should be 
fixable.  you can at least reuse the unmarshaller dict).

</F>




More information about the Python-list mailing list