[XML-SIG] fast dump/restore of an XML document?

Anthony Baxter Anthony Baxter <anthony@interlink.com.au>
Tue, 16 May 2000 19:10:37 +1000


>>> Greg Stein wrote
> xml.utils.qp_xml parses XML into a very lightweight structure. Those
> should be easily pickle-able. With a little bit of work, I bet they could
> be marshalled.
> 
> It definitely isn't a solution out of the box, but (IMO) it is a great
> head start on a Pythonic structure that is easily marshalled/pickled.

Hm - when I use qp_xml, I get 

  File "/opt/python/lib/python1.5/site-packages/xml/utils/qp_xml.py", line 144, in parse
    p.Parse(input, 1)
  File "/opt/python/lib/python1.5/site-packages/xml/utils/qp_xml.py", line 88, in start
    name = attrs[i]
KeyError: 0

putting 
    print "attrlen", len(attrs), type(attrs), attrs
before the offending line shows:
attrlen 2 <type 'dictionary'> {'name': 'Svalbard', 'ccode': 'AAX'}

a quick fix that wfm:

--- qp_xml.py.dist      Tue May 16 19:06:51 2000
+++ qp_xml.py   Tue May 16 19:04:55 2000
@@ -83,9 +83,9 @@
     work_attrs = [ ]
 
     # scan for namespace declarations (and xml:lang while we're at it)
-    for i in range(0, len(attrs), 2):
-      name = attrs[i]
-      value = attrs[i+1]
+    for i in attrs.keys():
+      name = i
+      value = attrs[i]
 
       if name == 'xmlns':
         elem.ns_scope[''] = value


with this fix, it happily parses my dataset. yay. 

Anthony