/usr/lib/python2.3/tabnanny.py xmlfile.py

This commit is contained in:
S.Çağlar Onur
2005-06-21 14:24:12 +00:00
parent ef24f9166d
commit 83052cfb82
+12 -12
View File
@@ -21,7 +21,7 @@ def getNodeText(node):
except IndexError: except IndexError:
return None return None
except AttributeError: # no node by that name except AttributeError: # no node by that name
return None return None
if child.nodeType == child.TEXT_NODE: if child.nodeType == child.TEXT_NODE:
return child.data return child.data
else: else:
@@ -132,7 +132,7 @@ class XmlFile(object):
self.dom.unlink() self.dom.unlink()
def readxml(self, fileName): def readxml(self, fileName):
self.dom = mdom.parse(fileName) self.dom = mdom.parse(fileName)
def writexml(self, fileName): def writexml(self, fileName):
f = file(fileName,'w') f = file(fileName,'w')
@@ -143,12 +143,12 @@ class XmlFile(object):
raise XmlError("Root tagname not " + self.rootTag + " as expected") raise XmlError("Root tagname not " + self.rootTag + " as expected")
def getNode(self, tagPath): def getNode(self, tagPath):
"""returns the *first* matching node for given tag path.""" """returns the *first* matching node for given tag path."""
self.verifyRootTag() self.verifyRootTag()
return getNode(self.dom.documentElement, tagPath) return getNode(self.dom.documentElement, tagPath)
def getAllNodes(self, tagPath): def getAllNodes(self, tagPath):
"""returns all nodes matching a given tag path.""" """returns all nodes matching a given tag path."""
self.verifyRootTag() self.verifyRootTag()
return getAllNodes(self.dom.documentElement, tagPath) return getAllNodes(self.dom.documentElement, tagPath)
@@ -168,14 +168,14 @@ class XmlFile(object):
def getChildElts(self, tagpath): def getChildElts(self, tagpath):
""" returns the children of the given path, only with given type """ """ returns the children of the given path, only with given type """
node = self.getNode(tagpath) node = self.getNode(tagpath)
try: try:
return filter(lambda x:x.nodeType == x.ELEMENT_NODE, node.childNodes) return filter(lambda x:x.nodeType == x.ELEMENT_NODE, node.childNodes)
except AttributeError: except AttributeError:
return None return None
def getChildText(self, tagpath): def getChildText(self, tagpath):
node = self.getNode(tagpath) node = self.getNode(tagpath)
if not node: if not node:
return None return None
return getNodeText(node) return getNodeText(node)