+ self.root = tree.getroot()
+ # set namespaces map
+ self.namespaces = dict(self.root.nsmap)
+ # If the 'None' exist, then it's pointing to the default namespace. This makes
+ # it hard for us to write xpath queries for the default naemspace because lxml
+ # wont understand a None prefix. We will just associate the default namespeace
+ # with a key named 'default'.
+ if None in self.namespaces:
+ default_namespace = self.namespaces.pop(None)
+ self.namespaces['default'] = default_namespace
+
+ # set schema
+ for key in self.root.attrib.keys():
+ if key.endswith('schemaLocation'):
+ # schema location should be at the end of the list
+ schema_parts = self.root.attrib[key].split(' ')
+ self.schema = schema_parts[1]
+ namespace, schema = schema_parts[0], schema_parts[1]
+ break