55"""
66import collections .abc
77import re
8+ import xml .etree .ElementTree as ET
89
910import arcpy
1011
11- from lxml import etree as ET
12-
1312from ...TopicCategory import TopicCategory
1413
1514TOPIC_CATEGORIES_DISPLAY_NAME_TO_ENUM = {e .display_name .lower (): e for e in TopicCategory }
@@ -47,13 +46,13 @@ def topicCategories_getter(self):
4746 raise NotImplementedError ("Metadata object currently has none or empty XML." )
4847
4948 metadata_xml_tree = ET .ElementTree (ET .fromstring (metadata_xml ))
50- topic_categories_xpath = "/metadata[@xml:lang= \" en \" ] /dataIdInfo/tpCat/TopicCatCd"
49+ topic_categories_xpath = ". /dataIdInfo/tpCat/TopicCatCd"
5150
5251 # get a list of topic elements
53- topic_category_elements = metadata_xml_tree .xpath (topic_categories_xpath )
52+ topic_category_elements = metadata_xml_tree .findall (topic_categories_xpath )
5453
5554 if not topic_category_elements :
56- # no elmeents found, return empty list
55+ # no elements found, return empty list
5756 return []
5857
5958 # convert each element value to a str
@@ -68,7 +67,7 @@ def topicCategories_setter(self, value):
6867
6968 # process value into elements
7069 if isinstance (value , str ):
71- # presume we were supplied a one or more topic categorie as a string, delimited
70+ # presume we were supplied a one or more topic categories as a string, delimited
7271 value = [s .strip () for s in re .split (",|;" , value )]
7372 elif isinstance (value , TopicCategory ):
7473 # a single enumerated type has been given, put in a list
@@ -80,20 +79,20 @@ def topicCategories_setter(self, value):
8079 elif not isinstance (value , collections .abc .Sequence ):
8180 raise ValueError ("Input 'topicCategories' value is not valid." )
8281
83- # value is now a sequence presumeably of either an enumerated type already, or a string representing the
82+ # value is now a sequence presumably of either an enumerated type already, or a string representing the
8483 # display name, the ISO name, or portal name.
8584 # attempt to resolve each sequence value to an enum and then create element
8685 value = [ET .Element ("TopicCatCd" , value = _str_to_topic_category (v ).value ) for v in value ]
8786
8887 # set elements in XML
89- topic_categories_parent_xpath = "/metadata[@xml:lang= \" en \" ] /dataIdInfo/tpCat"
88+ topic_categories_parent_xpath = ". /dataIdInfo/tpCat"
9089 metadata_xml_tree = ET .ElementTree (ET .fromstring (metadata_xml ))
91- topic_category_parent_element = next (iter (metadata_xml_tree .xpath (topic_categories_parent_xpath )), None )
90+ topic_category_parent_element = next (iter (metadata_xml_tree .findall (topic_categories_parent_xpath )), None )
9291 topic_category_parent_element .clear ()
9392 topic_category_parent_element .extend (value )
9493
9594 # save XML back to arcpy
96- self .xml = ET .tostring (metadata_xml_tree .getroot (), encoding = "utf-8" , pretty_print = False )
95+ self .xml = "<?xml version= \" 1.0 \" ?>{}" . format ( ET .tostring (metadata_xml_tree .getroot (), encoding = "unicode" ) )
9796
9897 topicCategories_prop = property (topicCategories_getter , topicCategories_setter )
9998
0 commit comments