Example #1
0
    def __mapXpathToFields(self, sourceData, map, responseData, index=1):
        for xpath in map.keySet():
            field = map.get(xpath)
            if xpath != "":
                xpathobj = DefaultXPath(xpath)
                if not self.defaultNamespace is None:
                    xpathobj.setNamespaceContext(
                        SimpleNamespaceContext(self.defaultNamespace))

                nodes = xpathobj.selectNodes(sourceData)

                if isinstance(field, JsonObject):
                    #The XPath key provides a dictionary containing sub xpath queries mapped to fields
                    i = 1
                    for node in nodes:
                        self.__mapXpathToFields(node, field, responseData, i)
                        i += 1
                else:
                    # Lists indicate we're copying the several fields
                    if isinstance(field, JSONArray):
                        for eachField in field:
                            self.__insertFieldData(nodes, eachField,
                                                   responseData, index)
                    # or just one field
                    else:
                        self.__insertFieldData(nodes, field, responseData,
                                               index)
    def __mapXpathToFields(self, sourceData, map, exceptions, defaultNS, responseData, index = 1):
        for xpath in map.keySet():
            field = map.get(xpath)
            self.log.debug("Checking xpath: '{}' for use with field '{}'", xpath, field)
            if xpath == "":
                self.log.debug("Ignoring unmapped field: '{}'", field)
            else:
                xpathobj = DefaultXPath(xpath)
                if (len(defaultNS) > 0):
                    self.log.debug("Using default namespace {}", defaultNS)
                    xpathobj.setNamespaceContext(SimpleNamespaceContext(defaultNS))
                try:
                    nodes = xpathobj.selectNodes(sourceData)
                    self.log.debug("Number of nodes found: {}", len(nodes))
                except Exception, e:
                    self.log.debug("XPath error: {}", e)

                if isinstance(field, JsonObject):
                    #The XPath key provides a dictionary containing sub xpath
                    #queries mapped to fields
                    i = 1
                    for node in nodes:
                        self.__mapXpathToFields(node, field, exceptions, defaultNS, responseData, i)
                        i += 1
                else:
                    # Lists indicate we're copying the several fields
                    if isinstance(field, JSONArray):
                        for eachField in field:
                            self.__insertFieldData(nodes, eachField, responseData, index, exceptions)
                    # or just one field
                    else:
                        self.__insertFieldData(nodes, field, responseData, index, exceptions)
Example #3
0
 def __mapXpathToFields(self, sourceData, map, responseData, index = 1):
     for xpath in map.keySet():
         field = map.get(xpath)
         if xpath != "":
             xpathobj = DefaultXPath(xpath)
             if not self.defaultNamespace is None:
                 xpathobj.setNamespaceContext(SimpleNamespaceContext(self.defaultNamespace))
                 
             nodes = xpathobj.selectNodes(sourceData)
             
             if isinstance(field, JsonObject):
                 #The XPath key provides a dictionary containing sub xpath queries mapped to fields
                 i = 1
                 for node in nodes:
                     self.__mapXpathToFields(node, field, responseData, i)
                     i += 1
             else:
                 # Lists indicate we're copying the several fields
                 if isinstance(field, JSONArray):
                     for eachField in field:
                         self.__insertFieldData(nodes, eachField, responseData, index)
                 # or just one field
                 else:
                     self.__insertFieldData(nodes, field, responseData, index)