#!/usr/bin/python # -*- coding: utf-8 -*- from BeautifulSoup import BeautifulStoneSoup log = open('log.xml', 'r').read() dalog = {} soup = BeautifulStoneSoup(log) messages = soup.findAll('msg') n = 0 for node in messages: dalog[n] = {} for f1, f2 in node.attrs: dalog[n][f1] = f2 dalog[n]['txt'] = node.txt.text n = n + 1 # Check first message node = dalog[0] for attr in node: print "%15s\t%s" % (attr, node[attr]) # Get all nodes #~ for node in dalog: #~ print dalog[node]['time'], dalog[node]['txt']
