Merge branch 'master' of github.com:sissaschool/elementpath
This commit is contained in:
commit
6bb5724a34
39
README.rst
39
README.rst
|
@ -21,11 +21,11 @@ You can install the package with *pip* in a Python 2.7 or Python 3.5+ environmen
|
||||||
|
|
||||||
For using it import the package and apply the selectors on ElementTree nodes:
|
For using it import the package and apply the selectors on ElementTree nodes:
|
||||||
|
|
||||||
>>> import elementpath
|
>>> import elementpath
|
||||||
>>> from xml.etree import ElementTree
|
>>> from xml.etree import ElementTree
|
||||||
>>> root = ElementTree.XML('<A><B1/><B2><C1/><C2/><C3/></B2></A>')
|
>>> root = ElementTree.XML('<A><B1/><B2><C1/><C2/><C3/></B2></A>')
|
||||||
>>> elementpath.select(root, '/A/B2/*')
|
>>> elementpath.select(root, '/A/B2/*')
|
||||||
[<Element 'C1' at ...>, <Element 'C2' at ...>, <Element 'C3' at ...>]
|
[<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
|
The *select* API provides the standard XPath result format that is a list or an elementary
|
||||||
datatype's value. If you want only to iterate over results you can use the generator function
|
datatype's value. If you want only to iterate over results you can use the generator function
|
||||||
|
@ -34,26 +34,25 @@ datatype's value. If you want only to iterate over results you can use the gener
|
||||||
The selectors API works also using XML data trees based on the `lxml.etree <http://lxml.de>`_
|
The selectors API works also using XML data trees based on the `lxml.etree <http://lxml.de>`_
|
||||||
library:
|
library:
|
||||||
|
|
||||||
>>> import elementpath
|
>>> import elementpath
|
||||||
>>> import lxml.etree as etree
|
>>> import lxml.etree as etree
|
||||||
>>> root = etree.XML('<A><B1/><B2><C1/><C2/><C3/></B2></A>')
|
>>> root = etree.XML('<A><B1/><B2><C1/><C2/><C3/></B2></A>')
|
||||||
>>> elementpath.select(root, '/A/B2/*')
|
>>> elementpath.select(root, '/A/B2/*')
|
||||||
[<Element C1 at ...>, <Element C2 at ...>, <Element C3 at ...>]
|
[<Element C1 at ...>, <Element C2 at ...>, <Element C3 at ...>]
|
||||||
|
|
||||||
|
|
||||||
When you need to apply the same XPath expression to several XML data you can also use the
|
When you need to apply the same XPath expression to several XML data you can also use the
|
||||||
*Selector* class, creating an instance and then using it to apply the path on distinct XML
|
*Selector* class, creating an instance and then using it to apply the path on distinct XML
|
||||||
data:
|
data:
|
||||||
|
|
||||||
>>> import elementpath
|
>>> import elementpath
|
||||||
>>> import lxml.etree as etree
|
>>> import lxml.etree as etree
|
||||||
>>> selector = elementpath.Selector('/A/*/*')
|
>>> selector = elementpath.Selector('/A/*/*')
|
||||||
>>> root = etree.XML('<A><B1/><B2><C1/><C2/><C3/></B2></A>')
|
>>> root = etree.XML('<A><B1/><B2><C1/><C2/><C3/></B2></A>')
|
||||||
>>> selector.select(root)
|
>>> selector.select(root)
|
||||||
[<Element C1 at ...>, <Element C2 at ...>, <Element C3 at ...>]
|
[<Element C1 at ...>, <Element C2 at ...>, <Element C3 at ...>]
|
||||||
>>> root = etree.XML('<A><B1><C0/></B1><B2><C1/><C2/><C3/></B2></A>')
|
>>> root = etree.XML('<A><B1><C0/></B1><B2><C1/><C2/><C3/></B2></A>')
|
||||||
>>> selector.select(root)
|
>>> selector.select(root)
|
||||||
[<Element C0 at ...>, <Element C1 at ...>, <Element C2 at ...>, <Element C3 at ...>]
|
[<Element C0 at ...>, <Element C1 at ...>, <Element C2 at ...>, <Element C3 at ...>]
|
||||||
|
|
||||||
Public API classes and functions are described into the
|
Public API classes and functions are described into the
|
||||||
`elementpath manual on the "Read the Docs" site <http://elementpath.readthedocs.io/en/latest/>`_.
|
`elementpath manual on the "Read the Docs" site <http://elementpath.readthedocs.io/en/latest/>`_.
|
||||||
|
|
|
@ -15,7 +15,7 @@ platforms:
|
||||||
- mac
|
- mac
|
||||||
softwareType: library
|
softwareType: library
|
||||||
inputTypes:
|
inputTypes:
|
||||||
- XML
|
- text/XML
|
||||||
categories:
|
categories:
|
||||||
- data-analytics
|
- data-analytics
|
||||||
- data-collection
|
- data-collection
|
||||||
|
@ -34,10 +34,9 @@ localisation:
|
||||||
availableLanguages:
|
availableLanguages:
|
||||||
- en
|
- en
|
||||||
it:
|
it:
|
||||||
|
countryExtensionVersion: '0.2'
|
||||||
riuso:
|
riuso:
|
||||||
codiceIPA: sissa
|
codiceIPA: sissa
|
||||||
piattaforme:
|
|
||||||
spid: false
|
|
||||||
description:
|
description:
|
||||||
en:
|
en:
|
||||||
genericName: elementpath
|
genericName: elementpath
|
||||||
|
@ -46,24 +45,29 @@ description:
|
||||||
shortDescription: >-
|
shortDescription: >-
|
||||||
Python library that provides XPath 1.0/2.0 parsers and selectors for
|
Python library that provides XPath 1.0/2.0 parsers and selectors for
|
||||||
ElementTree and lxml
|
ElementTree and lxml
|
||||||
longDescription: >+
|
longDescription: >
|
||||||
This is a library for Python 2.7/3.5+ that provides XPath 1.0 and 2.0
|
This is a library for Python 2.7/3.5+ that provides XPath 1.0 and 2.0
|
||||||
selectors for Python's ElementTree XML data structures, both for the
|
selectors for Python's ElementTree XML data structures, both for the
|
||||||
standard ElementTree library and for the lxml.etree library.
|
standard **ElementTree** library and for the **lxml** library. For lxml
|
||||||
|
this package can be useful for providing XPath 2.0 selectors, because lxml
|
||||||
|
already has it's own implementation of XPath 1.0.
|
||||||
For [lxml.etree](http://lxml.de/) this package can be useful for providing
|
|
||||||
XPath 2.0 selectors, because [lxml.etree](http://lxml.de/) already has
|
|
||||||
it's own implementation of XPath 1.0.
|
|
||||||
|
|
||||||
|
|
||||||
## Installation and usage
|
## Installation and usage
|
||||||
|
|
||||||
|
|
||||||
You can install the package with _pip_ in a Python 2.7 or Python 3.5+
|
You can install the package with _pip_ in a Python 2.7 or Python 3.5+
|
||||||
environment:
|
environment:
|
||||||
|
~~~
|
||||||
pip install elementpath
|
pip install elementpath
|
||||||
|
~~~
|
||||||
|
For 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 ...>]
|
||||||
|
~~~
|
||||||
|
|
||||||
features:
|
features:
|
||||||
- XPath 1.0 and XPath 2.0 implementations
|
- XPath 1.0 and XPath 2.0 implementations
|
||||||
|
|
Loading…
Reference in New Issue