Author: dmeyer
Date: Fri Mar 23 17:59:07 2007
New Revision: 2593
Modified:
trunk/base/src/xmlutils.py
Log:
return children by name with getattr
Modified: trunk/base/src/xmlutils.py
==============================================================================
--- trunk/base/src/xmlutils.py (original)
+++ trunk/base/src/xmlutils.py Fri Mar 23 17:59:07 2007
@@ -35,10 +35,11 @@
class SaxTreeHandler(xml.sax.ContentHandler):
"""
- Handler for the SAX parser. The memeber function 'handle' will
+ Handler for the SAX parser. The member function 'handle' will
be called everytime an element given on init is closed. The parameter
is the tree with this element as root. A node can either have children
- or text content.
+ or text content. The SaxTreeHandler is usefull for simple xml files
+ found in config files and information like epg data.
"""
class Node(object):
"""
@@ -51,7 +52,12 @@
self.content = ''
def getattr(self, attr):
- return self.attr.get(attr)
+ if self.attr.haskey(attr):
+ return self.attr.get(attr)
+ nodes = [ n for n in self.children if n.name = attr ]
+ if len(nodes) == 1:
+ return nodes[0]
+ return None
def __repr__(self):
return '<Node %s>' % self.name
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog