How to print an Objectified Element?
I have xml of the format:
<channel>
<games>
<game slot='1'>
<id>Bric A Bloc</id>
<title-text>BricABloc Hoorah</title-text>
<link>Fruit Splat</link>
开发者_开发百科 </game>
</games>
</channel>
I've parsed this xml using lxml.objectify
, via:
tree = objectify.parse(file)
There will potentially be a number of <game>
s underneath <games>
.
I understand that I can generate a list of <game>
objects via:
[ tree.games[0].game[0:4] ]
My question is, what class are those objects and is there a function to print any object of whatever class these objects belong to?
Perhaps use
for game in tree.games[0].game[0:4]:
print(lxml.objectify.dump(game))
which yields
game = None [ObjectifiedElement]
* slot = '1'
id = 'Bric A Bloc' [StringElement]
title-text = 'BricABloc Hoorah' [StringElement]
link = 'Fruit Splat' [StringElement]
print(game)
shows that each game
is an lxml.ojectify.ObjectifiedElement.
精彩评论