2010-06-06 38 views
1

我有格式的XML:如何打印物化元素?

<channel> 
    <games> 
     <game slot='1'> 
      <id>Bric A Bloc</id> 
      <title-text>BricABloc Hoorah</title-text> 
      <link>Fruit Splat</link> 
     </game> 
    </games> 
</channel> 

我解析使用lxml.objectify这个XML,通过:

tree = objectify.parse(file) 

有将有可能成为下<games>一些<game>秒。 我明白,我可以生成通过<game>对象的列表:

[ tree.games[0].game[0:4] ] 

我的问题是,什么类是那些对象,并在那里打印的任何种类的这些对象属于任何对象的功能?

回答

3

也许使用

for game in tree.games[0].game[0:4]: 
    print(lxml.objectify.dump(game)) 

其产生

game = None [ObjectifiedElement] 
    * slot = '1' 
    id = 'Bric A Bloc' [StringElement] 
    title-text = 'BricABloc Hoorah' [StringElement] 
    link = 'Fruit Splat' [StringElement] 

print(game)示出了每个gamelxml.ojectify.ObjectifiedElement