Peter Otten <__pete...@web.de> writes: > root = etree.fromstring(s) > for server in root.xpath("./server"): > servername = server.xpath("./name/text()")[0]
When working with lxml I prefer to use this Python idiom. servername, = server.xpath("./name/text()") That enforces a single result. The original code will detect a lack of results but if the query returns multiple results when only one is expected then it silently returns the first. -- Pete Forman -- https://mail.python.org/mailman/listinfo/python-list