Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath Query in XML using Python

Is it possible to use XPath Query in Python while processing XML. I am using minidom which doesn't support that. Is there any other module for that?

like image 597
Prabhu Avatar asked Aug 21 '09 09:08

Prabhu


People also ask

Can we use XPath in python?

XPath Standard Functions. XPath includes over 200 built-in functions. There are functions for string values, numeric values, booleans, date and time comparison, node manipulation, sequence manipulation, and much more. These expressions can be used in JavaScript, Java, XML Schema, Python, and lots of other languages.

What is XPath query in XML?

The XML Path Language (XPath) is used to uniquely identify or address parts of an XML document. An XPath expression can be used to search through an XML document, and extract information from any part of the document, such as an element or attribute (referred to as a node in XML) in it.

How do you traverse XML in Python?

There are two ways to parse the file using 'ElementTree' module. The first is by using the parse() function and the second is fromstring() function. The parse () function parses XML document which is supplied as a file whereas, fromstring parses XML when supplied as a string i.e within triple quotes.


1 Answers

http://docs.python.org/library/xml.etree.elementtree.html

etree supports XPath queries, just like lxml.

etree is included in the standard library, but lxml is faster.

like image 134
gonsalu Avatar answered Sep 26 '22 07:09

gonsalu