I will shortly be having this problem/question too. My thought was: use a wrapper function that first tries to get the elements without the namespace specified, and if that returns None
, then try with the namespace. If both return None, then the elements were not present. Using both functions (without if-else) works nicely if no default namespace is provided.
If the choice is between the same namespace either being specified or not, then I think ths approach above is okay. If you have multiple-optional-namespaces, it will make your wrapper more complicated but it's a one-time effort.
Would like to see a more elegant solution for this though. Did DanielHaley's answer work?
Related options:
- There's also this answer to specify the namespace in
find
,findall
, etc. - Could try
register_namespace
as per the solution here, which works for writing out. - This one suggests using
*
to find but that's too generic to use to find specific elements. - Suppress namespaces altogether
- If desperate, you can try using regex