Skip to content

Conversation

sangampaudel530
Copy link

@sangampaudel530 sangampaudel530 commented Oct 20, 2025

ElementTree.find, findall, findtext, and iterfind now use the global _namespace_map as fallback when no namespaces argument is provided. This fixes inconsistencies between ElementTree and ElementPath when using ET.register_namespace.

Example usage:

import xml.etree.ElementTree as ET
ET.register_namespace('h', 'http://www.w3.org/TR/html4/')
tree = ET.parse('xml/example.xml')
tree.find('.//h:title') # now works without manually passing namespaces

@bedevere-app
Copy link

bedevere-app bot commented Oct 20, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot
Copy link

python-cla-bot bot commented Oct 20, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Oct 21, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

ElementTree.find, findall, findtext, and iterfind now use the
global _namespace_map as fallback when no namespaces argument
is provided. Fixes inconsistencies between ElementTree and
ElementPath when using ET.register_namespace.
…izer (pythonGH-140123)

The namespace prefix resolution in ElementPath.xpath_tokenizer now properly uses globally
registered namespaces after trying local namespaces first. This ensures consistent namespace
handling across both Python and C implementations.
- Remove duplicate import of xml.etree.ElementTree as ET
- Add missing newline at end of NEWS entry file
ElementTree.find, findall, findtext, and iterfind now use the
global _namespace_map as fallback when no namespaces argument
is provided. Fixes inconsistencies between ElementTree and
ElementPath when using ET.register_namespace.
…izer (pythonGH-140123)

The namespace prefix resolution in ElementPath.xpath_tokenizer now properly uses globally
registered namespaces after trying local namespaces first. This ensures consistent namespace
handling across both Python and C implementations.
- Remove duplicate import of xml.etree.ElementTree as ET
- Add missing newline at end of NEWS entry file
@sangampaudel530 sangampaudel530 force-pushed the gh-140123-fix-elementtree-namespaces branch from 18a22ac to 8c6a6e4 Compare October 21, 2025 04:55
Fix issue where self.parser was incorrectly initialized in XMLParser.__init__.
The parser was being created twice and the wrong instance was being assigned.
Now both self.parser and self._parser point to the same parser instance,
maintaining backward compatibility and fixing the AttributeError in tests.
@AlexWaygood AlexWaygood removed their request for review October 21, 2025 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant