128
votes
8answers
90k views

How do I parse XML in python?

I have many rows in a database that contain xml and I'm trying to write a python script that will go through those rows and count how many instances of a particular node attribute show up. For ...
102
votes
11answers
43k views

Pretty printing XML in python

What is the best way (or even the various ways) to pretty print xml in python?
92
votes
9answers
79k views

How to use xpath in Python?

Is there a full implementation? How is the library used, where is its website?
43
votes
5answers
23k views

Validating with an XML schema in Python

Bounty: This is a 2 year old question. Is there a XSD validator for Python now? I have an XML file and an XML schema in another file and I'd like to validate that my XML file adheres to the ...
33
votes
3answers
16k views

Decode HTML entities in Python string?

I'm trying to work out if there is a better way to achieve the following: from lxml import html from BeautifulSoup import BeautifulSoup soup = BeautifulSoup("<p>&pound;682m</p>") ...
32
votes
15answers
4k views

XML Processing in Python

I'm about to build a piece of a project that will need to construct and post an XML document to a web service and I'd like to do it in Python, as a means to expand my skills in it. Unfortunately, ...
31
votes
10answers
20k views

Converting XML to JSON using Python?

I've seen a fair share of ungainly XML->JSON code on the web, and having interacted with Stack's users for a bit, I'm convinced that this crowd can help more than the first few pages of Google results ...
31
votes
4answers
10k views

XML parsing - ElementTree vs SAX and DOM

Python has several ways to parse XML... I understand the very basics of parsing with SAX. It functions as a stream parser, with an event-driven API. I understand the DOM parser also. It reads the ...
27
votes
8answers
24k views

XML writing tools for Python

I'm currently trying ElementTree and it looks fine, it escapes HTML entities and so on and so forth. Am I missing something truly wonderful I haven't heard of? This is similar to what I'm actually ...
26
votes
6answers
18k views

Serialize Python dictionary to XML

There is simple JSON serialization module with name "simplejson" which easily serializes Python objects to JSON. I'm looking for similar module which can serialize to XML.
23
votes
18answers
5k views

Viable alternative to XSLT?

I have used XSLT for a few different things over the years. I got used to it, but never felt like I really understood it all the way through. It always seems like I have to experiment to get the ...
22
votes
7answers
16k views

How to convert XML to JSON in Python? [duplicate]

Possible Duplicate: Converting XML to JSON using Python? I'm doing some work on App Engine and I need to convert an XML document being retrieved from a remote server into an equivalent JSON ...
21
votes
6answers
14k views

What is the fastest way to parse large XML docs in Python?

I am currently the following code based on Chapter 12.5 of the Python Cookbook: from xml.parsers import expat class Element(object): def __init__(self, name, attributes): self.name = ...
21
votes
4answers
11k views

Need Help using XPath in ElementTree

I am having a heck of a time using ElementTree 1.3 in Python. Essentially, ElementTree does absolutely nothing. My XML file looks like the following: <?xml version="1.0"?> ...
21
votes
5answers
18k views

How can I create a Word document using Python?

I'd like to create a Word document using Python, however, I want to re-use as much of my existing document-creation code as possible. I am currently using an XSLT to generate an HTML file that I ...

1 2 3 4 5 140
15 30 50 per page