Commits

Chris Mutel committed b31dad5

Improve ecospold1 import by relaxing namespace requirements

  • Participants
  • Parent commits aae31f0

Comments (0)

Files changed (1)

File bw2data/io/import_ecospold.py

         for index, filename in enumerate(files):
             root = objectify.parse(open(filename)).getroot()
 
-            if root.tag != '{http://www.EcoInvent.org/EcoSpold01}ecoSpold':
+            if root.tag not in (
+                    '{http://www.EcoInvent.org/EcoSpold01}ecoSpold',
+                    'ecoSpold'):
                 # Unrecognized file type
                 log.critical(u"skipping %s - no ecoSpold element" % filename)
                 continue
         data = []
         # Skip definitional exchange - we assume this already
         for exc in dataset.flowData.iterchildren():
-            if exc.tag == "{http://www.EcoInvent.org/EcoSpold01}exchange":
+            if exc.tag in (
+                    "{http://www.EcoInvent.org/EcoSpold01}exchange",
+                    "exchange"):
                 data.append(self.process_exchange(exc, dataset))
-            elif exc.tag == "{http://www.EcoInvent.org/EcoSpold01}allocation":
+            elif exc.tag in (
+                    "{http://www.EcoInvent.org/EcoSpold01}allocation",
+                    "allocation"):
                 data.append(self.process_allocation(exc, dataset))
             else:
-                raise ValueError("Flow data type %s no understood" % exc.tag)
+                raise ValueError("Flow data type %s not understood" % exc.tag)
         return data
 
     def process_allocation(self, exc, dataset):
         data = self.apply_transforms(data)
         data = self.add_hashes(data)
 
+        if not data:
+            self.log.critical("No data found in XML file %s" % path)
+            warnings.warn("No data found in XML file %s" % path)
+            return
+
         widgets = ['Linking exchanges:', progressbar.Percentage(), ' ',
             progressbar.Bar(marker=progressbar.RotatingMarker()), ' ',
             progressbar.ETA()]