-
Notifications
You must be signed in to change notification settings - Fork 0
/
Protocol.py
40 lines (33 loc) · 1.28 KB
/
Protocol.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as ET
import Field
class Protocol:
def __init__(self, name, showname, size, pos, show, value, plainXML):
self.name = name
self.showname = showname
self.size = size
self.pos = size
self.show = size
self.value = size
self.plainXML = plainXML
# Testing purposes
#print(plainXML)
self.fieldList = []
self.parseFields()
def parseFields(self):
tree = ET.ElementTree(ET.fromstring(self.plainXML))
root = tree.getroot()
# Getting all the fields
for child in root:
# Attributes of field
fieldName = child.get("name")
fieldShowname = child.get("showname")
fieldSize = child.get("size")
fieldPos = child.get("pos")
fieldValue = child.get("value")
fieldShow = child.get("show")
plainXML = ET.tostring(child, encoding='utf8').decode('utf8')
currField = Field.Field(fieldName, fieldShowname, fieldSize,
fieldPos, fieldShow, fieldValue, plainXML)
self.fieldList.append(currField)