xmlparser: fix parsing of subchild
This commit is contained in:
parent
1887e481d2
commit
8a25ebb45b
|
@ -83,7 +83,7 @@ class XMLParser:
|
||||||
@property
|
@property
|
||||||
def root(self):
|
def root(self):
|
||||||
if len(self.stack):
|
if len(self.stack):
|
||||||
return self.stack[0]
|
return self.stack[0][0]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -91,13 +91,13 @@ class XMLParser:
|
||||||
@property
|
@property
|
||||||
def current(self):
|
def current(self):
|
||||||
if len(self.stack):
|
if len(self.stack):
|
||||||
return self.stack[-1]
|
return self.stack[-1][0]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def display_stack(self):
|
def display_stack(self):
|
||||||
return " in ".join([str(type(s).__name__) for s in reversed(self.stack)])
|
return " in ".join([str(type(s).__name__) for s,c in reversed(self.stack)])
|
||||||
|
|
||||||
|
|
||||||
def startElement(self, name, attrs):
|
def startElement(self, name, attrs):
|
||||||
|
@ -105,7 +105,8 @@ class XMLParser:
|
||||||
if name not in self.knodes:
|
if name not in self.knodes:
|
||||||
raise TypeError(name + " is not a known type to decode")
|
raise TypeError(name + " is not a known type to decode")
|
||||||
else:
|
else:
|
||||||
self.stack.append(self.knodes[name](**attrs))
|
self.stack.append((self.knodes[name](**attrs), self.child))
|
||||||
|
self.child = 0
|
||||||
else:
|
else:
|
||||||
self.child += 1
|
self.child += 1
|
||||||
|
|
||||||
|
@ -116,19 +117,15 @@ class XMLParser:
|
||||||
|
|
||||||
|
|
||||||
def endElement(self, name):
|
def endElement(self, name):
|
||||||
if self.child:
|
|
||||||
self.child -= 1
|
|
||||||
|
|
||||||
if hasattr(self.current, "endElement"):
|
|
||||||
self.current.endElement(name)
|
|
||||||
return
|
|
||||||
|
|
||||||
if hasattr(self.current, "endElement"):
|
if hasattr(self.current, "endElement"):
|
||||||
self.current.endElement(None)
|
self.current.endElement(None)
|
||||||
|
|
||||||
|
if self.child:
|
||||||
|
self.child -= 1
|
||||||
|
|
||||||
# Don't remove root
|
# Don't remove root
|
||||||
if len(self.stack) > 1:
|
elif len(self.stack) > 1:
|
||||||
last = self.stack.pop()
|
last, self.child = self.stack.pop()
|
||||||
if hasattr(self.current, "addChild"):
|
if hasattr(self.current, "addChild"):
|
||||||
if self.current.addChild(name, last):
|
if self.current.addChild(name, last):
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user