I want to findall tags that match






I need to be able to grab anyone of those three tags, I think the parenthesis is throwing me off. I tried some regex and findall("*") works but after I go further I get no return.

closed as off-topic by user2856, Vince, BBG_GIS, BERA, Kadir Şahbaz Aug 16 '18 at 9:12

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions relating to general IT or with no clear GIS component, are off-topic here but can be researched/asked at Stack Overflow (software development), Super User (computing hardware and software), Database Administrators (relational databases) and other SE sites" – user2856, Vince, BBG_GIS, BERA, Kadir Şahbaz
If this question can be reworded to fit the rules in the help center, please edit the question.


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'):

#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'):

#As above but with simplified namespace handling
ns = {"fxl":"http://trimble.com/schema/fxl"}
for pfd in root.findall('.//fxl:FeatureDefinitions/fxl:PointFeatureDefinition', ns):

for pfd in root.findall('.//fxl:FeatureDefinitions/fxl:PointFeatureDefinition', ns):

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)

In your Regular expression, you'll have to escape some of the characters in your strings, because they are special characters in Regex syntax. Also you can group all three expressions into one easily because the only difference is the Point|Polyline|Polygon part.

The following expression should find what you want:


Could not get any of the xpath or regex expressions to work. First answer was the closest to this.

   for child in line+polygon+points:
       ##create feature class
       fcName=child.attrib.get('Code').replace(" ","_")

Not the answer you're looking for? Browse other questions tagged or ask your own question.