# -*- coding: utf-8 -*-

import os
import sys
import re

root_dir = os.path.normpath(os.path.dirname(os.path.abspath(__file__))).split(os.path.sep + 'tmp')[0]
# print root_dir
sys.path.insert(0, os.path.normpath(root_dir + os.path.sep + 'libs' + os.path.sep + 'libsDarwin'))
from bs4 import BeautifulSoup

'''
et = ElementTree.parse('/Users/lowitty/proj/aptana/zacademy/tmp/test.xml')
e = et.find('.//E')
H = ElementTree.Element('H')
H.attrib['text'] = "Hello \"Yannik\""
# H.tail = "\n\t\t"
e.append(H)
et.write('/Users/lowitty/proj/aptana/zacademy/tmp/test1.xml', encoding='utf-8', xml_declaration=True, method='xml')
i = 1
'''

'''
et = ElementTree.parse('/Users/lowitty/proj/aptana/zacademy/tmp/test3.xml')
H = et.find('.//BD')
print H.attrib['val']
'''

'''
f = open('/Users/lowitty/proj/aptana/zacademy/tmp/xx.txt', 'r+')
print f.readline().strip() == "'"
print "'"

print chr(39)
print "`"
'''

'''
bs = BeautifulSoup(open('/Users/lowitty/proj/pycharm/zacademy/tmp/test3.xml', 'r+'), 'html.parser')
e = bs.find(val=re.compile('event_name\w*'))
print e.parent()
'''

def find_parent_mine(element, tag='val'):
    return element.find_parent(attrs={tag : "header"})


from com.ericsson.xn.commons.XmlConverter import ConvertToXMLFromFile
c = ConvertToXMLFromFile('/Users/lowitty/proj/pycharm/zacademy/tmp/x.txt', '{', '}', 'val', True)
s = c.get_pretty_string()
# print s
dom = BeautifulSoup(s, 'html.parser')
event_name = dom.find(val=re.compile('event_name\w*'))
# print event_name.find(val="")


'''
event_type = dom.find(val="event_type")
print event_type.find(val="").find(attrs={'val' : re.compile('domain_name\s+.*')})
print 's  d f'.split(None, 1)
print event_type.find_next_sibling(val=re.compile('event_name\s+.*'))
'''

d = dom.find(val=re.compile('name\s+"d"'))
print d.find_next_sibling(val='value')