Be careful with the find and findall methods of the python standard library XML. etree. elementtree

Source: Internet
Author: User

In the python standard libraryXML. etree. elementtreeIt is easy to use and encapsulated for XML operations. However, there are some details that need to be noticed by users:
WhereXML. etree. elementtreeThe find and findall methods do not fully support XPath. Needless to say, xpath2.0 means that even xpath1.0 only supports a small part of xpath1.0. It can be said that it only supports a subset of xpath1.0.
The following example shows the problem:
Etree. Find ("Auto/process_thread_operate/Time ")
Etree. Find ("Auto/process_thread_operate/time [@ action = 'dns _ query']")
The running result is the same as expected, but if you run the following operations:
Etree. Find ("Auto/process_thread_operate/time [@ action = 'dns _ query' and @ action = 'HTTP _ access']")
An invalid predicate error is returned.
The reason is thatXML. etree. elementtree has limited support for xpath.
If you want to fully use XPath, we recommend that you use the lxml xpath

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.