Changeset 1455 for TI07-MOLES/trunk


Ignore:
Timestamp:
24/08/06 12:26:29 (13 years ago)
Author:
domlowe
Message:

getXMLRecord() can now retrieve a record where the id is an attribute (needed for CSML gml:id). Also namespaces of attributes can be declared and specified.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/PythonCode/existInterface/eXistGeneralInterface.py

    r1450 r1455  
    11# Code inspired by example on eXist website. 
    2 import urllib2, base64, urllib, urlparse, httplib, xmlrpclib, types 
     2import urllib2, base64, urllib, urlparse, httplib, xmlrpclib, types,sys 
    33 
    44class   InstanceObject(object): 
     
    131131            r='none' 
    132132        return r 
    133     #getXMLRecord gets any XML record, added by Dom 
    134     def getXMLRecord(self,collID,IDdefinition,itemID): 
    135         ''' Get a specific document from a collection in a repository by using the collection name and ID and ID element name ''' 
    136         xq='''for $DE in collection('%s')/*[%s='%s'] return $DE'''%(collID,IDdefinition,itemID) 
     133         
     134    def defineNamespace(self,abNS,fullNS): 
     135        #xq="declare namespace %s='%s'",(abNS,fullNS) 
     136        xq = '' 
    137137        id,summary=self.executeQuery(xq) 
    138138        if summary['hits']==1: 
     
    142142            r='none' 
    143143        return r 
     144     
     145    #getXMLRecord gets any XML record including ns:id as attribute, (added by Dom) 
     146    def getXMLRecord(self,collID,IDdefinition,itemID,att=None,namespaceLong=None,namespaceShort=None): 
     147        ''' Get a specific document from a collection in a repository by using the collection name and ID and ID element name ''' 
     148        if att: # ID is stored in an attribute 
     149            if namespaceLong and namespaceShort: #if attribute has namespace e.g. gml:id 
     150                xq='''declare namespace %s="%s"; for $DE in collection('%s')/*[@%s='%s'] return $DE'''%(namespaceShort,namespaceLong,collID,IDdefinition,itemID) 
     151            else: xq='''for $DE in collection('%s')/*[@%s='%s'] return $DE'''%(collID,IDdefinition,itemID) 
     152        else: 
     153            xq='''for $DE in collection('%s')/*[%s='%s'] return $DE'''%(collID,IDdefinition,itemID) 
     154        id,summary=self.executeQuery(xq) 
     155        if summary['hits']==1: 
     156            r=self.retrieve(id,0,{}) 
     157            self.sessionRelease(id) 
     158        else: 
     159            r='none' 
     160        return r 
     161     
    144162if __name__=="__main__": 
    145163     
     
    174192    print 'done getXMLRecord (MOLES)' 
    175193    #print existDB.chunkedFullText('badc') 
     194         
     195    print existDB.getXMLRecord('/db/ndg_A_metadata','gml:id','coapec_sample',att=1,namespaceLong='http://www.opengis.net/gml',namespaceShort='gml') 
     196    print 'done getXMLRecord with gml:id attribute (CSML)' 
    176197     
    177      
Note: See TracChangeset for help on using the changeset viewer.