-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml.py
More file actions
29 lines (28 loc) · 913 Bytes
/
Copy pathxml.py
File metadata and controls
29 lines (28 loc) · 913 Bytes
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
"""
A class to represent XML strings.
"""
class XML:
"""
XML Constructor. name is the tag name. contents is a list of XML objects
that are within this tag.
"""
def __init__(self, name, contents):
self.name = name
self.contents = contents
"""
Compare this XML with another XML. Returns true if they are the same
(meaning they have the same name and same tags in the same order and
recursively checks all of the inner tags all the way down) or false
otherwise.
"""
def compare(self, other):
if self.name != other.name:
return False
if len(self.contents) != len(other.contents):
return False
for i in range(len(self.contents)):
selfTag = self.contents[i]
otherTag = other.contents[i]
if not selfTag.compare(otherTag):
return False
return True