From bebf50e05ec6acb40367fb83e4a65e4c162eb3a1 Mon Sep 17 00:00:00 2001 From: Bob Lannon Date: Tue, 16 Apr 2013 16:58:46 -0400 Subject: [PATCH] added ability to specify attribute prefix for fields associated with XML attributes --- saucebrush/sources.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/saucebrush/sources.py b/saucebrush/sources.py index 04e346e..35b4ba1 100644 --- a/saucebrush/sources.py +++ b/saucebrush/sources.py @@ -285,11 +285,17 @@ class XMLSource(FileSource): super(XMLSource, self).__init__(input) self.node_list = node_list.split('.') - def _process_file(self, f): + def _process_file(self, f, attr_prefix='ATTR_'): + """xmltodict can either return attributes of nodes as prefixed fields + (prefixes to avoid key collisions), or ignore them altogether. + + set attr prefix to whatever you want. Setting it to False ignores + attributes. + """ import xmltodict - obj = xmltodict.parse(f) + obj = xmltodict.parse(f,attr_prefix=attr_prefix) # If node list was given, walk down the tree