支持python中XPath 2.0的库

发布于 2025-01-26 20:50:42 字数 286 浏览 5 评论 0原文

是否可以在Python中使用XPATH 2.0函数,例如starting-with(), end-with() and contectains()?我试图使用lxmldefusedxml,但不幸的是它们不支持这些功能。

我知道我可以使用substring()matches()用于解决方法,但是我确实很复杂,因此处理更可读的功能会更好。

任何支持XPath 2.0规格的LIB吗?

Is it possible to use XPath 2.0 functions like starts-with(), ends-with() and contains() in Python? I was trying to use lxml and defusedxml, but unfortunately they do not support any of these functions.

I know I can use substring() or matches() for workaround, but I have really complicated case, so it would be nicer to deal with more readable functions.

Any lib that supports XPath 2.0 spec?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

能怎样 2025-02-02 20:50:42

使用 elementpath 为此,它支持内置的XML.Etree模块,这可能是最容易的。和LXML。

>>> 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 ...>]

It's probably easiest to use elementpath for this, which supports the built-in xml.etree module and lxml.

>>> 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 ...>]
过去的过去 2025-02-02 20:50:42

saxonpy 基于Saxon He,并支持XPATH 2.0。
您可以检查GitHub存储库以获取一些示例以使您入门:

https://github.com/github.com/github.com/tennom/saxonm/saxonpy < /a>

saxonpy is based on Saxon He and supports Xpath 2.0.
You can check the github repo for some examples to get you started:

https://github.com/tennom/saxonpy

荒人说梦 2025-02-02 20:50:42

Saxonc 12.x的Python车轮是官方版本,您可以在此处找到: https> https:// pypi。 org/user/saxonica/

The python wheels for SaxonC 12.X is the official release, which you can find here: https://pypi.org/user/saxonica/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文