Massive import exceptions.
I really need a basic script that I can pass an argument to and it will convert the pickle to XML, and save it in the same directory as the source pickle.
If some one reading this knows how to work in python, I posted an example from some site that has code to convert it but.. I don't know python enough to strip it down to the most basic functions.
If the XML is valid, I can read it right back in to a dataset.
From there I can just take what ever I want from the tables.
Here is the XML section from that link:
Code: Select all
# -----------------------------------------------------------------------------
# XML
class Format_xml(Format):
"""Standard XML 1.0 using Python builtins."""
def __init__(self):
Format.__init__(self)
def dict2xml(self, dct, root='Root', indent='\t'):
"""Convert a dictionary to an XML string.
Rules:
string -> escape(string)
int, float -> as-is
dict -> <key>value</key>
tuple, list -> repeat tag for each value
bool -> int(bool)
None, empty string -> empty node
other object -> escape(str(obj))
"""
# from xml.sax.saxutils import escape
def tagset(key, val, level):
if val in (None, ""):
return "%s<%s />\n" % (indent*level, key)
if type(val) in (list, tuple):
return "".join(tagset(key, v, level) for v in val)
if type(val) is bool:
val = int(val)
return "%s<%s>%s</%s>\n" % (indent*level, key,
format_value(key, val, level), key)
def format_value(key, val, level):
if type(val) in (float, int, str):
pass
elif type(val) is dict:
lines = [tagset(k, v, level+1) for k, v in val.iteritems()]
lines.sort() # NB: Py dicts are unordered
val = "\n%s%s" % (''.join(lines), indent*level)
elif type(val) is not str:
val = str(val)
return val
return tagset(root, dct, 0)
def write(self, obj):
"""Serialize."""
return '<?xml version="1.0" encoding="UTF-8">\n' + \
self.dict2xml(obj.__dict__, root=__name__)