Ignore:
Timestamp:
05/10/10 16:23:24 (10 years ago)
Author:
astephen
Message:

fixed wps namespace in lookup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cows_wps/trunk/cows_wps/utils/common.py

    r7525 r7573  
    1717import urllib2 
    1818import Cookie 
     19import xml.etree.ElementTree as ET 
    1920 
    2021#from cows_wps.utils import case_sensitive_ordered_config_parser as cp 
     
    270271 
    271272 
     273def extractFromXML(xml, xml_path): 
     274    """ 
     275    Extracts a list of items from an XML string/doc. The list is found in 
     276    the xml_path lookup which is represented like a file path. E.g. 
     277 
     278        Extracts values at xml_path location within XML response 
     279        E.g. <person><job>nurse mother</job></person> and "person/job" will resturn ["nurse", "mother"] 
     280 
     281    """ 
     282#    fout = open("/tmp/xml.xml", "w"); fout.write(xml) ; fout.close() 
     283    node = ET.fromstring(xml) 
     284 
     285    namespace_map = {"gml": "http://www.opengis.net/gml", 
     286                     "wcs": "http://www.opengis.net/wcs", 
     287                     "ows": "http://www.opengeospatial.net/ows", 
     288                     "wps": "http://www.opengeospatial.net/wps",  
     289                    } 
     290 
     291    path_parts = xml_path.split("/")[1:] 
     292    this_node = node 
     293 
     294    for item in path_parts: 
     295        log.warn("item: %s" % str(this_node)) 
     296 
     297        for (id, ns) in namespace_map.items(): 
     298            if item.find("%s:" % id) == 0: 
     299                search_item = "{%s}%s" % (ns, item.split(":")[-1]) 
     300                break 
     301        else: 
     302            search_item = item 
     303 
     304        print this_node, search_item 
     305        this_node = this_node.find(search_item) 
     306        
     307 
     308    try: 
     309        extracted_list = this_node.text.split() 
     310        return extracted_list 
     311    except: 
     312        raise Exception("Could not extract element from XML using xml path: '%s'" % xml_path) 
     313 
     314  
    272315def mapDownloadURLToFilePath(url): 
    273316    from cows_wps.model.managers import requestManager 
Note: See TracChangeset for help on using the changeset viewer.