Sorting causes problems with import
### Description / Beschreibung

When using different `uri_prefix`es for, e.g. a domain import, the sorting by `uri` destroys the order in the file, and parent Attributes are imported *after* their children (with a different `uri_prefix` earlier in the alphabet). This is the problematic line:

https://github.com/rdmorganiser/rdmo/blob/master/rdmo/core/xml.py#L52

### Expected behaviour / Erwartetes Verhalten

I am not sure if we could get rid of the sorting, we could also sort by `path` (which would give the field some meaning in the xml again). Ideas? @triole @MyPyDavid 

diff --git a/rdmo/core/constants.py b/rdmo/core/constants.py
index f5be7b34..9a8d6a4f 100644
--- a/rdmo/core/constants.py
+++ b/rdmo/core/constants.py
@@ -55,3 +55,12 @@ PERMISSIONS = {
         'views.add_view', 'views.change_view', 'views.delete_view'
     )
 }
+
+IMPORT_SORT_ORDER = (
+    'domain',
+    'conditions',
+    'options',
+    'questions',
+    'tasks',
+    'views'
+)
diff --git a/rdmo/core/xml.py b/rdmo/core/xml.py
index 79612024..7f517c1d 100644
--- a/rdmo/core/xml.py
+++ b/rdmo/core/xml.py
@@ -3,6 +3,9 @@ import re
 
 import defusedxml.ElementTree as ET
 
+from .constants import IMPORT_SORT_ORDER
+
+
 log = logging.getLogger(__name__)
 
 
@@ -49,7 +52,7 @@ def flat_xml_to_elements(treenode):
 
         elements.append(element)
 
-    elements = sort_elements_by_key(elements, 'uri')
+    elements = sorted(elements, key=sort_elements)
     return elements
 
 
@@ -92,5 +95,13 @@ def filter_elements_by_type(elements, element_type):
             yield element
 
 
-def sort_elements_by_key(dictlist, key, reverse=False):
-    return sorted(dictlist, key=lambda k: k[key], reverse=reverse)
+def sort_elements(element):
+    # remove the uri_prefix from the uri to create the key to be sorted by
+    sort_key = element['uri'].replace(element['uri_prefix'], '')
+
+    # remove the app name from the sort_key and replace it by its import order
+    for i, item in enumerate(IMPORT_SORT_ORDER):
+        if sort_key.startswith(item):
+            sort_key = sort_key.replace(item, str(i))
+
+    return sort_key
['rdmo/core/constants.py', 'rdmo/core/xml.py']