Archive

Archive for the ‘XPath’ Category

XPath (libxml2) in Python

February 3, 2011 5 comments


Step 1: Install libxml2 using synaptic package manager

Step 2: Create an xml file that you want to traverse.

For example I am using w3school’s xml document http://www.w3schools.com/xpath/books.xml.
We can also use the local file exist on file system.

Step 3: Create a python for example having name xpathcode.py

Open the xpathcode.py import the libxml2 and urllib. Parse the xml file.

import libxml2
import urllib
rss=libxml2.parseDoc(urllib.urlopen('http://www.w3schools.com/xpath/books.xml').read())

Read more…

Categories: Python, XML, XPath