Revision: 29201
          http://sourceforge.net/p/bibdesk/svn/29201
Author:   hofman
Date:     2025-04-26 14:33:20 +0000 (Sat, 26 Apr 2025)
Log Message:
-----------
parse indivdual records

Modified Paths:
--------------
    trunk/bibdesk/BDSKSRUGroupServer.m

Modified: trunk/bibdesk/BDSKSRUGroupServer.m
===================================================================
--- trunk/bibdesk/BDSKSRUGroupServer.m  2025-04-26 13:56:18 UTC (rev 29200)
+++ trunk/bibdesk/BDSKSRUGroupServer.m  2025-04-26 14:33:20 UTC (rev 29201)
@@ -40,8 +40,10 @@
 #import "BDSKServerInfo.h"
 #import "BDSKStringParser.h"
 #import "BDSKMARCParser.h"
+#import "BibItem.h"
 #import "NSString_BDSKExtensions.h"
 #import "NSURL_BDSKExtensions.h"
+#import "BDSKStringConstants.h"
 
 #define MAX_RESULTS 100
 
@@ -247,7 +249,7 @@
                 NSXMLElement *root = [document rootElement];
                 
                 // we need to extract WebEnv, Count, and QueryKey to construct 
our final URL
-                NSString *countString = [[[root 
nodesForXPath:@"/zs:searchRetrieveResponse[1]/zs:numberOfRecords[1]" 
error:NULL] lastObject] stringValue];
+                NSString *countString = [[[root 
nodesForXPath:@"/zs:searchRetrieveResponse[1]/zs:numberOfRecords[1]" 
error:NULL] firstObject] stringValue];
                 
                 availableResults = [countString integerValue];
                 
@@ -265,34 +267,49 @@
         }
         case BDSKFetchState:
         {
-            
-            NSString *string = [[NSString alloc] initWithData:data 
encoding:NSUTF8StringEncoding];
-            NSArray *pubs = nil;
-            
-            if ([BDSKMARCParser canParseString:string]) {
-                pubs = [BDSKMARCParser itemsFromString:string 
error:&presentableError];
-            } else {
-                BDSKStringType stringType = [string contentStringType];
-                if (stringType != BDSKStringTypeUnknown)
-                    pubs = [BDSKStringParser itemsFromString:string 
ofType:stringType error:&presentableError];
-            }
-            
             // the number of returned results is not always equal to what we 
requested
             // fetchedResults should track the requests to get the correct 
offset
             fetchedResults += requestedResults;
             
-            if (nil == pubs) {
+            // parse the result opf the search
+            NSXMLDocument *document = nil;
+            if (data)
+                document = [[NSXMLDocument alloc] initWithData:data 
options:NSXMLNodeOptionsNone error:NULL];
+
+            if (nil != document) {
+                NSXMLElement *root = [document rootElement];
+                
+                NSArray *records = [root 
nodesForXPath:@"/zs:searchRetrieveResponse[1]/zs:records[1]/zs.record/zs.recordData"
 error:NULL];
+                
+                NSMutableArray *pubs = [NSMutableArray array];
+                
+                for (NSXMLNode *node in records) {
+                    NSString *string = [[[node children] firstObject] 
XMLString] ?: @"";
+                    BibItem *pub = nil;
+                    
+                    if ([BDSKMARCParser canParseString:string]) {
+                        pub = [[BDSKMARCParser itemsFromString:string 
error:NULL] firstObject];
+                    } else {
+                        BDSKStringType stringType = [string contentStringType];
+                        if (stringType != BDSKStringTypeUnknown)
+                            pub = [[BDSKStringParser itemsFromString:string 
ofType:stringType error:NULL] firstObject];
+                    }
+                    if (pub == nil)
+                        pub = [[BibItem alloc] initWithType:BDSKBookString 
citeKey:nil pubFields:@{BDSKAnnoteString: string}];
+                    [pubs addObject:pub];
+
+                }
+                
+                // set before addPublications:
+                downloadState = BDSKIdleState;
+                [group addPublications:pubs];
+            } else {
                 failedDownload = YES;
-                [self setErrorMessage:[presentableError localizedDescription] 
?: NSLocalizedString(@"Could not retrieve results", @"")];
+                [self setErrorMessage:NSLocalizedString(@"Could not retrieve 
results", @"")];
                 // set before addPublications:
                 downloadState = BDSKIdleState;
                 [group addPublications:nil];
             }
-            else {
-                // set before addPublications:
-                downloadState = BDSKIdleState;
-                [group addPublications:pubs];
-            }
             break;
         }
         case BDSKIdleState:

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to