|
1
|
This recipe uses DOM (precisely, cDomlette or the minidom variant in 4Suite) to merge two files containing XBEL boomark listings. It uses Python 2.2. generators for straightforward and efficient iteration over the XBEL DOM trees in document order. It requires Python 2.2 and 4Suite 0.12.0a2 or more recent versions.
This is actually an updated version of an old script I posted ages ago: http://mail.python.org/pipermail/xml-sig/1999-September/001441.html This version is much faster and uses current APIs. For more info on XBEL, see: http://pyxml.sourceforge.net/topics/xbel/ An alternate implementation could use straight Python 2.2 minidom. The main changes would be using "minidom.parse" instead of "NonvalidatingReader.parseUri" and "new_xbel.toxml()" instead of "PrettyPrint(new_xbel)". For a great introduction to generators, about which I can hardly rave enough, see: http://www-106.ibm.com/developerworks/library/l-pycon.html http://www-106.ibm.com/developerworks/linux/library/l-pythrd.html To test this script, you can use the following 2 XBEL files: Bookmarks of Joris Graaumans [excerpt]
and Bookmarks of Joris Graaumans [excerpt]
Just call "python xbel_merge.py bm1.xbel bm2.xbel" and the results will go to stdout.
Tags: xml
|
1 comment
Add a comment
Sign in to comment
Download
Copy to clipboard

The sample XML files got corrupted. Looks as of the Cookbook uploader can't take XML in the "notes" field. Yes. I tried preview, and it did show the tags, though with indentation removed. Nothing like what showed up in the end. I've put the 2 XBEL files you can use for testing at
http://uche.ogbuji.net/etc/020625/bm1.xbel
and
http://uche.ogbuji.net/etc/020625/bm2.xbel
Sorry for any inconvenience.