Using re and elementtree
import re
import xml.etree.ElementTree as ET
def extract(stream):
r = re.compile('\}(?P\w+)')
tree = ET.fromsrting(stream)
dfeed = {}
dfeed[r.search(tree.tag).group(1)] = None # feed
l0_node = dict()
for node in tree: # l0
l1_children = node.getchildren()
l1_node = dict()
if l1_children: # l1
for l1_child in l1_children:
l2_children = l1_child.getchildren()
l2_node = dict()
if l2_children: # l2
for l2_child in l2_children:
l3_children = l2_child.getchildren()
l3_node = dict()
if l3_children: #l3
for l3_child in l3_children:
l3_node[r.search(l3_child.tag).group(1)] = l3_child.text
l2_node[r.search(l2_child.tag).group(1)] = l3_node
else:
l2_node[r.search(l2_child.tag).group(1)] = l2_child.text
l1_node[r.search(l1_child.tag).group(1)] = l2_node
else:
l1_node[r.search(l1_child.tag).group(1)] = l1_child.text
l0_node[r.search(node.tag).group(1)] = l1_node
else:
l0_node[r.search(node.tag).group(1)] = node.text
dfeed[r.search(tree.tag).group(1)] = l0_node
return dfeed
import xml.etree.ElementTree as ET
def extract(stream):
r = re.compile('\}(?P
tree = ET.fromsrting(stream)
dfeed = {}
dfeed[r.search(tree.tag).group(1)] = None # feed
l0_node = dict()
for node in tree: # l0
l1_children = node.getchildren()
l1_node = dict()
if l1_children: # l1
for l1_child in l1_children:
l2_children = l1_child.getchildren()
l2_node = dict()
if l2_children: # l2
for l2_child in l2_children:
l3_children = l2_child.getchildren()
l3_node = dict()
if l3_children: #l3
for l3_child in l3_children:
l3_node[r.search(l3_child.tag).group(1)] = l3_child.text
l2_node[r.search(l2_child.tag).group(1)] = l3_node
else:
l2_node[r.search(l2_child.tag).group(1)] = l2_child.text
l1_node[r.search(l1_child.tag).group(1)] = l2_node
else:
l1_node[r.search(l1_child.tag).group(1)] = l1_child.text
l0_node[r.search(node.tag).group(1)] = l1_node
else:
l0_node[r.search(node.tag).group(1)] = node.text
dfeed[r.search(tree.tag).group(1)] = l0_node
return dfeed
Hai, How are you today?nice blog you have
ReplyDeleteCheers
Watch Unco Twister Coco Funny Video
http://cocofunnyvideo.blogspot.com/2010/10/unco-twister-coco-funny-video.html