Esempio n. 1
0
def _get_spatial_operator(geomattr, element, dbtype, nsmap):
    ''' return the spatial predicate function '''
    property_name = element.find(util.nspath_eval('ogc:PropertyName', nsmap))
    distance = element.find(util.nspath_eval('ogc:Distance', nsmap))

    distance = 'false' if distance is None else distance.text

    if property_name is None:
        raise RuntimeError, \
        ('Missing ogc:PropertyName in spatial filter')
    if (property_name.text.find('BoundingBox') == -1
            and property_name.text.find('Envelope') == -1):
        raise RuntimeError, \
        ('Invalid ogc:PropertyName in spatial filter: %s' %
        property_name.text)

    geometry = gml.Geometry(element, nsmap)

    spatial_predicate = util.xmltag_split(element.tag).lower()

    if dbtype == 'mysql':  # adjust spatial query for MySQL
        if spatial_predicate == 'bbox':
            spatial_predicate = 'intersects'

        if spatial_predicate == 'beyond':
            spatial_query = "ifnull(distance(geomfromtext(%s), \
            geomfromtext('%s')) > convert(%s, signed),false)"                                                              % \
            (geomattr, geometry.wkt, distance)
        elif spatial_predicate == 'dwithin':
            spatial_query = "ifnull(distance(geomfromtext(%s), \
            geomfromtext('%s')) <= convert(%s, signed),false)"                                                               % \
            (geomattr, geometry.wkt, distance)
        else:
            spatial_query = "ifnull(%s(geomfromtext(%s), \
            geomfromtext('%s')),false)" % (spatial_predicate, geomattr,
                                           geometry.wkt)

    elif dbtype == 'postgresql+postgis':  # adjust spatial query for PostGIS
        if spatial_predicate == 'bbox':
            spatial_predicate = 'intersects'

        if spatial_predicate == 'beyond':
            spatial_query = "not st_dwithin(st_geomfromtext(%s), \
            st_geomfromtext('%s'), %f)" % (geomattr, geometry.wkt,
                                           float(distance))
        elif spatial_predicate == 'dwithin':
            spatial_query = "st_dwithin(st_geomfromtext(%s), \
            st_geomfromtext('%s'), %f)" % (geomattr, geometry.wkt,
                                           float(distance))
        else:
            spatial_query = "st_%s(st_geomfromtext(%s), \
            st_geomfromtext('%s'))" % (spatial_predicate, geomattr,
                                       geometry.wkt)
    else:
        spatial_query = "query_spatial(%s,'%s','%s','%s')" % \
        (geomattr, geometry.wkt, spatial_predicate, distance)

    return spatial_query
Esempio n. 2
0
File: fes.py Progetto: drwelby/pycsw
def _get_spatial_operator(geomattr, element, dbtype, nsmap):
    ''' return the spatial predicate function '''
    property_name = element.find(util.nspath_eval('ogc:PropertyName', nsmap))
    distance = element.find(util.nspath_eval('ogc:Distance', nsmap))

    distance = 'false' if distance is None else distance.text

    if property_name is None:
        raise RuntimeError, \
        ('Missing ogc:PropertyName in spatial filter')
    if (property_name.text.find('BoundingBox') == -1 and
        property_name.text.find('Envelope') == -1):
        raise RuntimeError, \
        ('Invalid ogc:PropertyName in spatial filter: %s' %
        property_name.text)

    geometry = gml.Geometry(element, nsmap)

    spatial_predicate = util.xmltag_split(element.tag).lower()

    if dbtype == 'mysql':  # adjust spatial query for MySQL
        if spatial_predicate == 'bbox':
            spatial_predicate = 'intersects'

        if spatial_predicate == 'beyond':
            spatial_query = "ifnull(distance(geomfromtext(%s), \
            geomfromtext('%s')) > convert(%s, signed),false)" % \
            (geomattr, geometry.wkt, distance)
        elif spatial_predicate == 'dwithin':
            spatial_query = "ifnull(distance(geomfromtext(%s), \
            geomfromtext('%s')) <= convert(%s, signed),false)" % \
            (geomattr, geometry.wkt, distance)
        else:
            spatial_query = "ifnull(%s(geomfromtext(%s), \
            geomfromtext('%s')),false)" % (spatial_predicate, geomattr, geometry.wkt)

    elif dbtype == 'postgresql+postgis':  # adjust spatial query for PostGIS
        if spatial_predicate == 'bbox':
            spatial_predicate = 'intersects'

        if spatial_predicate == 'beyond':
            spatial_query = "not st_dwithin(st_geomfromtext(%s), \
            st_geomfromtext('%s'), %f)" % (geomattr, geometry.wkt, float(distance))
        elif spatial_predicate == 'dwithin':
            spatial_query = "st_dwithin(st_geomfromtext(%s), \
            st_geomfromtext('%s'), %f)" % (geomattr, geometry.wkt, float(distance))
        else:
            spatial_query = "st_%s(st_geomfromtext(%s), \
            st_geomfromtext('%s'))" % (spatial_predicate, geomattr, geometry.wkt)
    else:
        spatial_query = "query_spatial(%s,'%s','%s','%s')" % \
        (geomattr, geometry.wkt, spatial_predicate, distance)

    return spatial_query
Esempio n. 3
0
File: gml.py Progetto: drwelby/pycsw
    def __init__(self, element, nsmap):
        ''' initialize geometry parser  '''

        self.nsmap = nsmap
        self.type = None
        self.wkt = None
        self.crs = None
        self._exml = element
        ''' return OGC WKT for GML geometry '''

        operand = element.xpath(
            '|'.join(TYPES), namespaces={'gml':
                                         'http://www.opengis.net/gml'})[0]

        if operand.attrib.has_key('srsName'):
            self.crs = crs.Crs(operand.attrib['srsName'])
        else:
            self.crs = DEFAULT_SRS

        self.type = util.xmltag_split(operand.tag)

        if util.xmltag_split(operand.tag) == 'Point':
            self._get_point()
        elif util.xmltag_split(operand.tag) == 'LineString':
            self._get_linestring()
        elif util.xmltag_split(operand.tag) == 'Polygon':
            self._get_polygon()
        elif util.xmltag_split(operand.tag) == 'Envelope':
            self._get_envelope()
        else:
            raise RuntimeError, \
            ('Unsupported geometry type (Must be one of %s)' % ','.join(TYPES))

        # reproject data if needed
        if self.crs is not None and self.crs.code != 4326:
            try:
                self.wkt = self.transform(self.crs.code, DEFAULT_SRS.code)
            except Exception, err:
                raise RuntimeError, \
                ('Reprojection error: Invalid srsName "%s": %s' %
                (self.crs.id, str(err)))
Esempio n. 4
0
    def __init__(self, element, nsmap):
        ''' initialize geometry parser  '''

        self.nsmap = nsmap
        self.type = None 
        self.wkt = None
        self.crs = None
        self._exml = element

        ''' return OGC WKT for GML geometry '''
    
        operand = element.xpath(
        '|'.join(TYPES), namespaces={'gml':'http://www.opengis.net/gml'})[0]

        if operand.attrib.has_key('srsName'):
            self.crs = crs.Crs(operand.attrib['srsName'])
        else:
            self.crs = DEFAULT_SRS

        self.type = util.xmltag_split(operand.tag)

        if util.xmltag_split(operand.tag) == 'Point':
            self._get_point()
        elif util.xmltag_split(operand.tag) == 'LineString':
            self._get_linestring()
        elif util.xmltag_split(operand.tag) == 'Polygon':
            self._get_polygon()
        elif util.xmltag_split(operand.tag) == 'Envelope':
            self._get_envelope()
        else:
            raise RuntimeError, \
            ('Unsupported geometry type (Must be one of %s)' % ','.join(TYPES))

        # reproject data if needed    
        if self.crs is not None and self.crs.code != 4326:
            try:
                self.wkt = self.transform(self.crs.code, DEFAULT_SRS.code)
            except Exception, err:
                raise RuntimeError, \
                ('Reprojection error: Invalid srsName "%s": %s' %
                (self.crs.id, str(err)))
Esempio n. 5
0
    def response_csw2opensearch(self, element, cfg):
        ''' transform a CSW response into an OpenSearch response '''

        if util.xmltag_split(element.tag) == 'GetRecordsResponse':

            startindex = int(element.xpath('//@nextRecord')[0]) - int(element.xpath('//@numberOfRecordsReturned')[0])
            if startindex < 1:
                startindex = 1

            node = etree.Element(util.nspath_eval('atom:feed', self.context.namespaces), nsmap=self.namespaces)
            etree.SubElement(node, util.nspath_eval('atom:id', self.context.namespaces)).text = cfg.get('server', 'url')
            etree.SubElement(node, util.nspath_eval('atom:title', self.context.namespaces)).text = cfg.get('metadata:main', 'identification_title')
            #etree.SubElement(node, util.nspath_eval('atom:updated', self.context.namespaces)).text = element.xpath('//@timestamp')[0]
                
            etree.SubElement(node, util.nspath_eval('opensearch:totalResults', self.context.namespaces)).text = element.xpath('//@numberOfRecordsMatched')[0]
            etree.SubElement(node, util.nspath_eval('opensearch:startIndex', self.context.namespaces)).text = str(startindex)
            etree.SubElement(node, util.nspath_eval('opensearch:itemsPerPage', self.context.namespaces)).text = element.xpath('//@numberOfRecordsReturned')[0]
            
            for rec in element.xpath('//atom:entry', namespaces=self.context.namespaces):
                node.append(rec)
            
        return node
Esempio n. 6
0
    def response_csw2sru(self, element, environ):
        ''' transform a CSW response into an SRU response '''

        if util.xmltag_split(element.tag) == 'Capabilities':  # explain
            node = etree.Element(util.nspath_eval('sru:explainResponse',
                                                  self.namespaces),
                                 nsmap=self.namespaces)

            etree.SubElement(node,
                             util.nspath_eval(
                                 'sru:version',
                                 self.namespaces)).text = self.sru_version

            record = etree.SubElement(
                node, util.nspath_eval('sru:record', self.namespaces))

            etree.SubElement(
                record, util.nspath_eval('sru:recordPacking',
                                         self.namespaces)).text = 'XML'
            etree.SubElement(
                record, util.nspath_eval('sru:recordSchema', self.namespaces)
            ).text = 'http://explain.z3950.org/dtd/2.1/'

            recorddata = etree.SubElement(
                record, util.nspath_eval('sru:recordData', self.namespaces))

            explain = etree.SubElement(
                recorddata, util.nspath_eval('zr:explain', self.namespaces))

            serverinfo = etree.SubElement(explain,
                                          util.nspath_eval(
                                              'zr:serverInfo',
                                              self.namespaces),
                                          protocol='SRU',
                                          version=self.sru_version,
                                          transport='http',
                                          method='GET POST SOAP')

            etree.SubElement(serverinfo,
                             util.nspath_eval(
                                 'zr:host',
                                 self.namespaces)).text = environ.get(
                                     'HTTP_HOST', environ["SERVER_NAME"]
                                 )  # WSGI allows for either of these
            etree.SubElement(
                serverinfo, util.nspath_eval(
                    'zr:port', self.namespaces)).text = environ['SERVER_PORT']
            etree.SubElement(serverinfo,
                             util.nspath_eval('zr:database',
                                              self.namespaces)).text = 'pycsw'

            databaseinfo = etree.SubElement(
                explain, util.nspath_eval('zr:databaseInfo', self.namespaces))

            etree.SubElement(databaseinfo,
                             util.nspath_eval('zr:title', self.namespaces),
                             lang='en',
                             primary='true').text = element.xpath(
                                 '//ows:Title',
                                 namespaces=self.context.namespaces)[0].text
            etree.SubElement(databaseinfo,
                             util.nspath_eval('zr:description',
                                              self.namespaces),
                             lang='en',
                             primary='true').text = element.xpath(
                                 '//ows:Abstract',
                                 namespaces=self.context.namespaces)[0].text

            indexinfo = etree.SubElement(
                explain, util.nspath_eval('zr:indexInfo', self.namespaces))
            etree.SubElement(indexinfo,
                             util.nspath_eval('zr:set', self.namespaces),
                             name='dc',
                             identifier='info:srw/cql-context-set/1/dc-v1.1')

            for key, value in self.mappings['csw:Record']['index'].iteritems():
                zrindex = etree.SubElement(indexinfo,
                                           util.nspath_eval(
                                               'zr:index', self.namespaces),
                                           id=value)
                etree.SubElement(zrindex,
                                 util.nspath_eval('zr:title',
                                                  self.namespaces)).text = key
                zrmap = etree.SubElement(
                    zrindex, util.nspath_eval('zr:map', self.namespaces))
                etree.SubElement(zrmap,
                                 util.nspath_eval('zr:map', self.namespaces),
                                 set='dc').text = key

            zrindex = etree.SubElement(
                indexinfo, util.nspath_eval('zr:index', self.namespaces))
            zrmap = etree.SubElement(
                zrindex, util.nspath_eval('zr:map', self.namespaces))
            etree.SubElement(zrmap,
                             util.nspath_eval('zr:name', self.namespaces),
                             set='dc').text = 'title222'

            schemainfo = etree.SubElement(
                explain, util.nspath_eval('zr:schemaInfo', self.namespaces))
            zrschema = etree.SubElement(schemainfo,
                                        util.nspath_eval(
                                            'zr:schema', self.namespaces),
                                        name='dc',
                                        identifier='info:srw/schema/1/dc-v1.1')
            etree.SubElement(zrschema,
                             util.nspath_eval(
                                 'zr:title',
                                 self.namespaces)).text = 'Simple Dublin Core'

            configinfo = etree.SubElement(
                explain, util.nspath_eval('zr:configInfo', self.namespaces))
            etree.SubElement(configinfo,
                             util.nspath_eval('zr:default', self.namespaces),
                             type='numberOfRecords').text = '0'

        elif util.xmltag_split(element.tag) == 'GetRecordsResponse':

            recpos = int(element.xpath('//@nextRecord')[0]) - int(
                element.xpath('//@numberOfRecordsReturned')[0])

            node = etree.Element(util.nspath_eval('zs:searchRetrieveResponse',
                                                  self.namespaces),
                                 nsmap=self.namespaces)
            etree.SubElement(node,
                             util.nspath_eval(
                                 'zs:version',
                                 self.namespaces)).text = self.sru_version
            etree.SubElement(
                node, util.nspath_eval('zs:numberOfRecords',
                                       self.namespaces)).text = element.xpath(
                                           '//@numberOfRecordsMatched')[0]

            for rec in element.xpath('//csw:BriefRecord',
                                     namespaces=self.context.namespaces):
                record = etree.SubElement(
                    node, util.nspath_eval('zs:record', self.namespaces))
                etree.SubElement(
                    node, util.nspath_eval(
                        'zs:recordSchema',
                        self.namespaces)).text = 'info:srw/schema/1/dc-v1.1'
                etree.SubElement(
                    node, util.nspath_eval('zs:recordPacking',
                                           self.namespaces)).text = 'xml'

                recorddata = etree.SubElement(
                    record, util.nspath_eval('zs:recordData', self.namespaces))
                rec.tag = util.nspath_eval('srw_dc:srw_dc', self.namespaces)
                recorddata.append(rec)

                etree.SubElement(
                    record,
                    util.nspath_eval('zs:recordPosition',
                                     self.namespaces)).text = str(recpos)
                recpos += 1

        elif util.xmltag_split(element.tag) == 'ExceptionReport':
            node = self.exceptionreport2diagnostic(element)
        return node
Esempio n. 7
0
def _get_comparison_operator(element):
    ''' return the SQL operator based on Filter query '''

    return MODEL['ComparisonOperators']\
    ['ogc:%s' % util.xmltag_split(element.tag)]['opvalue']
Esempio n. 8
0
def parse(element, queryables, dbtype, nsmap):
    ''' OGC Filter object support '''

    boq = None

    tmp = element.xpath('ogc:And|ogc:Or|ogc:Not', namespaces=nsmap)
    if len(tmp) > 0:  # this is binary logic query
        boq = ' %s ' % util.xmltag_split(tmp[0].tag).lower()
        tmp = tmp[0]
    else:
        tmp = element

    queries = []

    for child in tmp.xpath('child::*'):
        com_op = ''
        boolean_true = '\'true\''
        boolean_false = '\'false\''

        if dbtype == 'mysql':
            boolean_true = 'true'
            boolean_false = 'false'

        if child.tag == util.nspath_eval('ogc:Not', nsmap):
            queries.append("%s = %s" % (_get_spatial_operator(
                queryables['pycsw:BoundingBox'],
                child.xpath('child::*')[0], dbtype, nsmap), boolean_false))

        elif child.tag in \
        [util.nspath_eval('ogc:%s' % n, nsmap) for n in \
        MODEL['SpatialOperators']['values']]:
            if boq is not None and boq == ' not ':
                # for ogc:Not spatial queries in PostGIS we must explictly
                # test that pycsw:BoundingBox is null as well
                if dbtype == 'postgresql+postgis':
                    queries.append(
                        "%s = %s or %s is null" %
                        (_get_spatial_operator(queryables['pycsw:BoundingBox'],
                                               child, dbtype, nsmap),
                         boolean_false, queryables['pycsw:BoundingBox']))
                else:
                    queries.append("%s = %s" % (_get_spatial_operator(
                        queryables['pycsw:BoundingBox'], child, dbtype,
                        nsmap), boolean_false))
            else:
                queries.append("%s = %s" % (_get_spatial_operator(
                    queryables['pycsw:BoundingBox'], child, dbtype,
                    nsmap), boolean_true))

        elif child.tag == util.nspath_eval('ogc:FeatureId', nsmap):
            queries.append(
                "%s = '%s'" %
                (queryables['pycsw:Identifier'], child.attrib.get('fid')))

        else:
            fname = None
            matchcase = child.attrib.get('matchCase')
            wildcard = child.attrib.get('wildCard')
            singlechar = child.attrib.get('singleChar')

            if wildcard is None:
                wildcard = '%'

            if singlechar is None:
                singlechar = '_'

            if (child.xpath('child::*')[0].tag == util.nspath_eval(
                    'ogc:Function', nsmap)):
                if (child.xpath('child::*')[0].attrib['name']
                        not in MODEL['Functions'].keys()):
                    raise RuntimeError, (
                        'Invalid ogc:Function: %s' %
                        (child.xpath('child::*')[0].attrib['name']))
                fname = child.xpath('child::*')[0].attrib['name']

                try:
                    pname = queryables[child.find(
                        util.nspath_eval('ogc:Function/ogc:PropertyName',
                                         nsmap)).text]['dbcol']
                except Exception, err:
                    raise RuntimeError, (
                        'Invalid PropertyName: %s.  %s' % (child.find(
                            util.nspath_eval('ogc:Function/ogc:PropertyName',
                                             nsmap)).text, str(err)))

            else:
                try:
                    pname = queryables[child.find(
                        util.nspath_eval('ogc:PropertyName',
                                         nsmap)).text]['dbcol']
                except Exception, err:
                    raise RuntimeError, (
                        'Invalid PropertyName: %s.  %s' %
                        (child.find(util.nspath_eval('ogc:PropertyName',
                                                     nsmap)).text, str(err)))
Esempio n. 9
0
def parse(element, queryables, dbtype, nsmap):
    ''' OGC Filter object support '''

    boq = None

    tmp = element.xpath('ogc:And|ogc:Or|ogc:Not', namespaces=nsmap)
    if len(tmp) > 0:  # this is binary logic query
        boq = ' %s ' % util.xmltag_split(tmp[0].tag).lower()
        tmp = tmp[0]
    else:
        tmp = element

    queries = []

    for child in tmp.xpath('child::*'):
        com_op = ''
        boolean_true = '\'true\''
        boolean_false = '\'false\''

        if dbtype == 'mysql':
            boolean_true = 'true'
            boolean_false = 'false'

        if child.tag == util.nspath_eval('ogc:Not', nsmap):
            queries.append("%s = %s" %
            (_get_spatial_operator(queryables['pycsw:BoundingBox'],
            child.xpath('child::*')[0], dbtype, nsmap), boolean_false))

        elif child.tag in \
        [util.nspath_eval('ogc:%s' % n, nsmap) for n in \
        MODEL['SpatialOperators']['values']]:
            if boq is not None and boq == ' not ':
                queries.append("%s = %s" %
                (_get_spatial_operator(queryables['pycsw:BoundingBox'],
                 child, dbtype, nsmap), boolean_false))
            else:
                queries.append("%s = %s" % 
                (_get_spatial_operator(queryables['pycsw:BoundingBox'],
                 child, dbtype, nsmap), boolean_true))

        elif child.tag == util.nspath_eval('ogc:FeatureId', nsmap):
            queries.append("%s = '%s'" % (queryables['pycsw:Identifier'],
            child.attrib.get('fid')))

        else:
            fname = None
            matchcase = child.attrib.get('matchCase')
            wildcard = child.attrib.get('wildCard')
            singlechar = child.attrib.get('singleChar')

            if wildcard is None:
                wildcard = '%'

            if singlechar is None:
                singlechar = '_'

            if (child.xpath('child::*')[0].tag ==
                util.nspath_eval('ogc:Function', nsmap)):
                if (child.xpath('child::*')[0].attrib['name'] not in
                MODEL['Functions'].keys()):
                    raise RuntimeError, ('Invalid ogc:Function: %s' %
                    (child.xpath('child::*')[0].attrib['name']))
                fname = child.xpath('child::*')[0].attrib['name']

                try:
                    pname = queryables[child.find(
                    util.nspath_eval('ogc:Function/ogc:PropertyName',
                    nsmap)).text]['dbcol']
                except Exception, err:
                    raise RuntimeError, ('Invalid PropertyName: %s.  %s' %
                    (child.find(util.nspath_eval('ogc:Function/ogc:PropertyName',
                    nsmap)).text,
                    str(err)))

            else:
                try:
                    pname = queryables[child.find(
                    util.nspath_eval('ogc:PropertyName', nsmap)).text]['dbcol']
                except Exception, err:
                    raise RuntimeError, ('Invalid PropertyName: %s.  %s' %
                    (child.find(util.nspath_eval('ogc:PropertyName',
                     nsmap)).text,
                     str(err)))
Esempio n. 10
0
def _get_comparison_operator(element):
    ''' return the SQL operator based on Filter query '''

    return MODEL['ComparisonOperators']\
    ['ogc:%s' % util.xmltag_split(element.tag)]['opvalue'] 
Esempio n. 11
0
    def response_csw2sru(self, element, environ):
        ''' transform a CSW response into an SRU response '''

        if util.xmltag_split(element.tag) == 'Capabilities':  # explain
            node = etree.Element(util.nspath_eval('sru:explainResponse', self.namespaces),
            nsmap=self.namespaces)

            etree.SubElement(node, util.nspath_eval('sru:version', self.namespaces)).text = self.sru_version

            record = etree.SubElement(node, util.nspath_eval('sru:record', self.namespaces))

            etree.SubElement(record, util.nspath_eval('sru:recordPacking', self.namespaces)).text = 'XML'
            etree.SubElement(record, util.nspath_eval('sru:recordSchema', self.namespaces)).text = 'http://explain.z3950.org/dtd/2.1/'

            recorddata = etree.SubElement(record, util.nspath_eval('sru:recordData', self.namespaces))

            explain = etree.SubElement(recorddata, util.nspath_eval('zr:explain', self.namespaces))

            serverinfo = etree.SubElement(explain, util.nspath_eval('zr:serverInfo', self.namespaces),
            protocol='SRU', version=self.sru_version, transport='http', method='GET POST SOAP')

            etree.SubElement(serverinfo, util.nspath_eval('zr:host', self.namespaces)).text = environ.get('HTTP_HOST', environ["SERVER_NAME"]) # WSGI allows for either of these
            etree.SubElement(serverinfo, util.nspath_eval('zr:port', self.namespaces)).text = environ['SERVER_PORT']
            etree.SubElement(serverinfo, util.nspath_eval('zr:database', self.namespaces)).text = 'pycsw'

            databaseinfo = etree.SubElement(explain, util.nspath_eval('zr:databaseInfo', self.namespaces))

            etree.SubElement(databaseinfo, util.nspath_eval('zr:title', self.namespaces), lang='en', primary='true').text = element.xpath('//ows:Title', namespaces=self.context.namespaces)[0].text
            etree.SubElement(databaseinfo, util.nspath_eval('zr:description', self.namespaces), lang='en', primary='true').text = element.xpath('//ows:Abstract', namespaces=self.context.namespaces)[0].text

            indexinfo = etree.SubElement(explain, util.nspath_eval('zr:indexInfo', self.namespaces))
            etree.SubElement(indexinfo, util.nspath_eval('zr:set', self.namespaces), name='dc', identifier='info:srw/cql-context-set/1/dc-v1.1')

            for key, value in self.mappings['csw:Record']['index'].iteritems():
                zrindex = etree.SubElement(indexinfo, util.nspath_eval('zr:index', self.namespaces), id=value)
                etree.SubElement(zrindex, util.nspath_eval('zr:title', self.namespaces)).text = key
                zrmap = etree.SubElement(zrindex, util.nspath_eval('zr:map', self.namespaces))
                etree.SubElement(zrmap, util.nspath_eval('zr:map', self.namespaces), set='dc').text = key

            zrindex = etree.SubElement(indexinfo, util.nspath_eval('zr:index', self.namespaces))
            zrmap = etree.SubElement(zrindex, util.nspath_eval('zr:map', self.namespaces))
            etree.SubElement(zrmap, util.nspath_eval('zr:name', self.namespaces), set='dc').text = 'title222'

            schemainfo = etree.SubElement(explain, util.nspath_eval('zr:schemaInfo', self.namespaces))
            zrschema = etree.SubElement(schemainfo, util.nspath_eval('zr:schema', self.namespaces), name='dc', identifier='info:srw/schema/1/dc-v1.1')
            etree.SubElement(zrschema, util.nspath_eval('zr:title', self.namespaces)).text = 'Simple Dublin Core'

            configinfo = etree.SubElement(explain, util.nspath_eval('zr:configInfo', self.namespaces))
            etree.SubElement(configinfo, util.nspath_eval('zr:default', self.namespaces), type='numberOfRecords').text = '0'

        elif util.xmltag_split(element.tag) == 'GetRecordsResponse':

            recpos = int(element.xpath('//@nextRecord')[0]) - int(element.xpath('//@numberOfRecordsReturned')[0])

            node = etree.Element(util.nspath_eval('zs:searchRetrieveResponse', self.namespaces), nsmap=self.namespaces)
            etree.SubElement(node, util.nspath_eval('zs:version', self.namespaces)).text = self.sru_version
            etree.SubElement(node, util.nspath_eval('zs:numberOfRecords', self.namespaces)).text = element.xpath('//@numberOfRecordsMatched')[0]

            for rec in element.xpath('//csw:BriefRecord', namespaces=self.context.namespaces):
                record = etree.SubElement(node, util.nspath_eval('zs:record', self.namespaces))
                etree.SubElement(node, util.nspath_eval('zs:recordSchema', self.namespaces)).text = 'info:srw/schema/1/dc-v1.1'
                etree.SubElement(node, util.nspath_eval('zs:recordPacking', self.namespaces)).text = 'xml'

                recorddata = etree.SubElement(record, util.nspath_eval('zs:recordData', self.namespaces))
                rec.tag = util.nspath_eval('srw_dc:srw_dc', self.namespaces)
                recorddata.append(rec)

                etree.SubElement(record, util.nspath_eval('zs:recordPosition', self.namespaces)).text = str(recpos)
                recpos += 1

        elif util.xmltag_split(element.tag) == 'ExceptionReport':
            node = self.exceptionreport2diagnostic(element)
        return node