-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata_type.py
More file actions
65 lines (45 loc) · 1.31 KB
/
metadata_type.py
File metadata and controls
65 lines (45 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
__author__ = 'chrissbarnett'
import xml.etree.ElementTree as ET
def get_metadata_type(xml_string):
doc = get_doc(xml_string)
root_tag = doc.getroot().tag.lower()
if is_iso_root(root_tag):
metadata_type = "ISO19139"
elif is_fgdc_root(root_tag):
metadata_type = "FGDC"
else:
raise Exception("Unknown metadata type")
return metadata_type, doc
def is_iso_root(root_tag):
return "md_metadata" in root_tag or "mi_metadata" in root_tag
def is_fgdc_root(root_tag):
if "metadata" in root_tag:
return not is_iso_root(root_tag)
def get_doc(xml_string):
try:
parser = ET.XMLParser(encoding="utf-8")
el = ET.XML(xml_string, parser=parser)
tree = ET.ElementTree(element=el)
return tree
except UnicodeEncodeError, e:
print e
print xml_string
raise e
except ET.ParseError as e:
print e.message
print xml_string
raise e
'''
eventually, we'll want to add in resource locations, source info
for item in objs:
try:
root = ET.fromstring(value)
origin = root.findtext("idinfo/citation/citeinfo/origin")
print origin
except UnicodeEncodeError, e:
print layerId
print e
except ET.ParseError, e1:
print layerId
print e1
'''