source: cows/trunk/cows/xml/util.py @ 2519

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/trunk/cows/xml/util.py@4032
Revision 2519, 919 bytes checked in by spascoe, 13 years ago (diff)

Added code to parse service metadata XML into ows_common objects.
Some corrections to ows_common classes.

Line 
1# Copyright (C) 2007 STFC & NERC (Science and Technology Facilities Council).
2# This software may be distributed under the terms of the
3# Q Public License, version 1.0 or later.
4# http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
5"""
6Elementtree convenience utilities
7
8@author: Stephen Pascoe
9
10"""
11
12def find_text(node, path):
13    """Find a node's text or None
14
15    """
16    return getattr(node.find(path), 'text', None)
17
18def findall_text(node, path):
19    """Find all n.text elements from a path.
20
21    """
22    return [n.text for n in node.findall(path)]
23
24def find_with(node, path, func):
25    """If node.find(path) returns a node n return func(n) else return None.
26
27    """
28    n = node.find(path)
29    if n is None:
30        return None
31    else:
32        return func(n)
33
34def findall_with(node, path, func):
35    """Find all func(n) for n in node.findall(path).
36
37    """
38    return [func(n) for n in node.findall(path)]
39
Note: See TracBrowser for help on using the repository browser.