def EndParsing(self): children = self.children self.if_then_else = False if any(isinstance(node, (ThenNode, ElseNode)) for node in children): if (len(children) != 2 or not isinstance(children[0], ThenNode) or not isinstance(children[1], ElseNode)): raise exception.UnexpectedChild( '<if> element must be <if><then>...</then><else>...</else></if>') self.if_then_else = True
def AddChild(self, child): '''Adds a child to the list of children of this node, if it is a valid child for the node.''' assert isinstance(child, Node) if (not self._IsValidChild(child) or self._ContentType() == self._CONTENT_TYPE_CDATA): explanation = 'invalid child %s for parent %s' % (str(child), self.name) raise exception.UnexpectedChild(explanation) self.children.append(child) self.mixed_content.append(child)
def AddChild(self, child): '''Adds a child to the list of children of this node, if it is a valid child for the node.''' assert isinstance(child, Node) if (not self._IsValidChild(child) or self._ContentType() == self._CONTENT_TYPE_CDATA): if child.parent: explanation = 'child %s of parent %s' % (child.name, child.parent.name) else: explanation = 'node %s with no parent' % child.name raise exception.UnexpectedChild(explanation) self.children.append(child) self.mixed_content.append(child)