L D
L D

Reputation: 143

Convert lxml object into string

I've just started using lxml, and I got this problem:

In the XML find I have an element with an attribute, for example:

<book category="COOKING">

I'm fine until the point I use:

for elt in doc.getiterator():

   ...

     a=elt.attrib

I get this object back: {'category': 'COOKING'}

How could I convert this into something usable, like a string?

Upvotes: 0

Views: 1009

Answers (1)

bcoughlan
bcoughlan

Reputation: 26627

The attrib property is a dictionary (i.e. associative array). To get the category property value as a string you can write elt.attrib['category']

Upvotes: 1

Related Questions