pip install elementpath | xml.etree.elementtree python install
TheproposalofthispackageistoprovideXPath1.0and2.0selectorsforPython’sElementTreeXMLdatastructures,bothforthestandardElementTreelibraryandforthelxml.etree[1]library.Forlxml.etree[2]thispackagecanbeusefulforprovidingXPath2.0selectors,becauselxml.etree[3]alreadyhasit’sownimplementationofXPath1.0.InstallationandusageYoucaninstallthepackagewithpipinaPython3.6+environment:pipinstallelementpathForusingitimportthepackageandapplytheselectorsonElementTreenodes:>>>importelementpath>>>...
The proposal of this package is to provide XPath 1.0 and 2.0 selectors for Python’s ElementTree XML data structures, both for the standard ElementTree library and for the lxml.etree[1] library.
For lxml.etree[2] this package can be useful for providing XPath 2.0 selectors, because lxml.etree[3] already has it’s own implementation of XPath 1.0.
Installation and usageYou can install the package with pip in a Python 3.6+ environment:
pip install elementpathFor using it import the package and apply the selectors on ElementTree nodes:
>>> import elementpath >>> from xml.etree import ElementTree >>> root = ElementTree.XML(<A><B1/><B2><C1/><C2/><C3/></B2></A>) >>> elementpath.select(root, /A/B2/*) [<Element C1 at ...>, <Element C2 at ...>, <Element C3 at ...>]The select API provides the standard XPath result format that is a list or an elementary datatype’s ...