Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=======================================================================================================================
- class TagDepth(object):
- def __init__(self):
- self.tag_depth = []
- def get_tree(self):
- val = ''
- for tag in self.tag_depth:
- val += (tag + '|')
- return val
- def rem(self):
- if len(self.tag_depth) > 0:
- del self.tag_depth[-1]
- def add(self, tag_name):
- self.tag_depth.append(tag_name)
- #=======================================================================================================================
- file_name = './poms/ws/pom.xml'
- tag_ex = ['modelVersion', '?xml', 'packaging']
- tag_found = False
- row = col = 1
- tag_name = pc = c = ''
- tag_depth = TagDepth()
- artifact = []
- with open(file_name, encoding='utf8') as file:
- while True:
- pc, c = c, file.read(1)
- col += 1
- if c == '':
- break
- if c == '\n':
- row += 1
- col = 1
- continue
- if tag_found:
- if c == '/' and pc == '<':
- tag_found = False
- tag_depth.rem()
- continue
- elif c == '>':
- tag_found = False
- if len(tag_name) > 0 and not tag_name in tag_ex:
- print(row, ' ', col, ' ', tag_depth.get_tree() + tag_name)
- tag_depth.add(tag_name)
- continue
- elif c != ' ':
- tag_name += c
- else:
- tag_found = False
- tag_depth.add(tag_name)
- if c == '<':
- tag_found = True
- tag_name = ''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement