You don't use a regex to parse XML, you use your XML parser.
I suggest you look at the ElementTree XPath and Namespaces documentation.
To answer your question, you can do something like the following
import xml.etree.ElementTree as et
tree = et.parse(fxl_file)
root = tree.getroot()
#Any PointFeatureDefinition elements
for pfd in root.findall('.//{http://trimble.com/schema/fxl}PointFeatureDefinition'):
print(pfd.tag)
#Only PointFeatureDefinition elements that are the direct child of FeatureDefinitions
for pfd in root.findall('.//{http://trimble.com/schema/fxl}FeatureDefinitions/{http://trimble.com/schema/fxl}PointFeatureDefinition'):
print(pfd.tag)
#As above but with simplified namespace handling
ns = {"fxl":"http://trimble.com/schema/fxl"}
for pfd in root.findall('.//fxl:FeatureDefinitions/fxl:PointFeatureDefinition', ns):
print(pfd.tag)
for pfd in root.findall('.//fxl:FeatureDefinitions/fxl:PointFeatureDefinition', ns):
print(pfd.tag)
You would repeat the findall
for PolylineFeatureDefinition
and PolygonFeatureDefinition
elements. Unless you're using lxml
, which supports a less limited XPath syntax so you could use the "or" | operator and do something like (untested):
root.findall('.//fxl:FeatureDefinitions/fxl:PointFeatureDefinition|fxl:LineFeatureDefinition|fxl:PolygonFeatureDefinition]', ns)