{"id":1470,"library":"elementpath","title":"ElementPath","description":"ElementPath is a comprehensive Python library providing XPath 1.0, 2.0, 3.0, and 3.1 parsers and selectors. It works seamlessly with both Python's built-in `ElementTree` and the more performant `lxml` library. Currently at version 5.1.1, it maintains a regular release cadence, typically releasing new versions monthly or bi-monthly, often including bug fixes, performance improvements, and Python version compatibility updates.","status":"active","version":"5.1.1","language":"en","source_language":"en","source_url":"https://github.com/sissaschool/elementpath","tags":["xml","xpath","lxml","elementtree","parser","data-processing"],"install":[{"cmd":"pip install elementpath","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary function for selecting nodes using an XPath expression.","symbol":"select","correct":"from elementpath import select"},{"note":"Used for creating reusable XPath selector objects, especially for complex or frequently used expressions.","symbol":"Selector","correct":"from elementpath import Selector"},{"note":"For advanced usage involving custom contexts, variables, or functions.","symbol":"XPathContext","correct":"from elementpath.xpath_context import XPathContext"}],"quickstart":{"code":"import xml.etree.ElementTree as ET\nfrom elementpath import select\n\nxml_string = \"\"\"\n<root>\n    <item id=\"1\">First item</item>\n    <item id=\"2\">Second item</item>\n    <item id=\"3\">Third item</item>\n</root>\n\"\"\"\n\n# Parse the XML string using ElementTree\nroot = ET.fromstring(xml_string)\n\n# Select all 'item' elements under 'root'\nitems = select(root, '/root/item')\n\n# Extract text from selected items\nresults = [item.text for item in items]\n\nprint(results)\n# Expected output: ['First item', 'Second item', 'Third item']","lang":"python","description":"This example demonstrates how to parse an XML string using `ElementTree` and then use `elementpath.select` to query elements with an XPath expression. It prints the text content of all 'item' elements found."},"warnings":[{"fix":"Ensure your Python environment is running Python 3.10 or newer. Upgrade your Python interpreter if you encounter `ImportError` or other compatibility issues.","message":"Python 3.8 and 3.9 compatibility was dropped in recent major versions. `elementpath` v5.0.0 dropped support for Python 3.8, and v5.1.0 dropped support for Python 3.9.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Review any code that directly interacts with `elementpath`'s internal parsing mechanisms. Most users relying on the high-level `select` or `Selector` APIs should not be affected.","message":"The internal XML parser was replaced. `SafeXMLParser` was removed and replaced with `SafeExpatParser` in version 5.0.0. This is an internal change but could affect users who relied on direct access to or configuration of the previous parser.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"If you have custom node handling or extensions, you may need to update your code to align with the new `XPathNodeTree` structure. Consult the official documentation for details on the new node model.","message":"Internal node tree structure changed significantly with the introduction of `XPathNodeTree` as the backbone for node representation. This impacts advanced users extending the library or introspecting its internal data structures.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Provide a namespace map when calling `select` or `Selector`. For example: `select(root, '/ns:root/ns:item', namespaces={'ns': 'http://example.com/ns'})`.","message":"XPath expressions often require explicit handling of XML namespaces. If your XML document uses namespaces and your XPath expressions don't account for them, you might get no results or incorrect ones.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}