English 中文(简体)
ISBN -> bookdata Lookup to fill in a database
原标题:

Ok, I wanting to database a small library.

I ve only had limited experience with databases, and none with querying from a webserver.

I m going to want to retrieve information like title, Publisher, maybe author, description the simplest way I can think of dooing this is looking them up via the ISBN.

I ve come across isbndb.com before, but the API for accessing it seems rather complex.

I m wondering how I should go about doing this.

最佳回答

I recently had to do exactly this as we indexed our library for insurance purposes. Below is the code of the vba class I hacked together:

Option Compare Database
    dim BookTitle As String
    dim BookTitleLong As String
    dim BookAuthorsText As String
    dim BookPublisherText As String
    dim BookSummary As String
    dim BookNotes As String
    dim accessKey As String

Private Sub Class_Initialize()
     Your isbnDB access key 
    accessKey = "PUT ACCESSKEY HERE"
End Sub    
Property Get Title() As String
    Title = BookTitle
End Property    
Property Get TitleLong() As String
    TitleLong = BookTitleLong
End Property    
Property Get AuthorsText() As String
    AuthorsText = BookAuthorsText
End Property
Property Get PublisherText() As String
    PublisherText = BookPublisherText
End Property
Property Get Summary() As String
    Summary = BookSummary
End Property
Property Get Notes() As String
    Notes = BookNotes
End Property

Public Function Lookup(isbn As String) As Boolean
    Lookup = False
    Dim xmlhttp
    Set xmlhttp = CreateObject("MSXML2.xmlhttp")
    xmlhttp.Open "GET", "https://isbndb.com/api/books.xml?access_key=" & accessKey & "&results=texts&index1=isbn&value1=" & isbn, False
    xmlhttp.send
     Debug.Print "Response: " & xmlhttp.responseXML.XML 
    Dim xmldoc
    Set xmldoc = CreateObject("Microsoft.XMLDOM")
    xmldoc.async = False
     Note: the ResponseXml property parses the server s response, responsetext doesn t
    xmldoc.loadXML (xmlhttp.responseXML.XML)
    If (xmldoc.selectSingleNode("//BookList").getAttribute("total_results") = 0) Then
        MsgBox "Invalid ISBN or not in database"
        Exit Function
    End If
    If (xmldoc.selectSingleNode("//BookList").getAttribute("total_results") > 1) Then
        MsgBox "Caution, got more than one result!"
        Exit Function
    End If
    BookTitle = xmldoc.selectSingleNode("//BookData/Title").Text
    BookTitleLong = xmldoc.selectSingleNode("//BookData/TitleLong").Text
    BookAuthorsText = xmldoc.selectSingleNode("//BookData/AuthorsText").Text
    BookPublisherText = xmldoc.selectSingleNode("//BookData/PublisherText").Text
    BookNotes = xmldoc.selectSingleNode("//BookData/Notes").Text
    BookSummary = xmldoc.selectSingleNode("//BookData/Summary").Text
    Lookup = True
End Function

Get an API key, paste the above code (with your key) into a new class module in the VBA editor (Insert->Class Module) and name the module "isbn". You also need to add a reference to "Microsoft XML" in the VBA editor (Tools->References)

You can test it works with the code snippet below in a normal vba module:

Public Function testlookup()
    Dim book
    Set book = New isbn
    book.Lookup ("0007102968")
    Debug.Print book.Title
    Debug.Print book.PublisherText
End Function

Then just type "testlookup" into the immediate window (View->Immediate Window). You should see a response of:

The Times book of quotations
[Glasgow] : Times Books : 2000.

isbnDB can return more than the data I collect in the above class, read the API reference here: http://isbndb.com/docs/api/ and tailor the class to your needs.

I found this article very helpful in explaining how to use xmlhttp from within access: http://www.15seconds.com/issue/991125.htm

The msdn pages on XML DOM Methods and XMLHttpRequest Object were also useful (because I m a new user I can only post two active links, you ll have to replace the dots in the urls below):

msdn microsoft com/en-us/library/ms757828(v=VS.85).aspx

msdn microsoft com/en-us/library/ms535874(v=vs.85).aspx

问题回答

This is an incomplete answer, but it should get you started (I ve not worked with XML data as return).

This code has the basics:

  Dim oHttp As Object

  Set oHttp = CreateObject("Microsoft.XMLHTTP")
  oHttp.Open "GET", "https://isbndb.com/api/books.xml?access_key=YourKey&results=texts&index1=isbn&value1=YourISBN", False
  oHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  oHttp.Send vbNullString
  Debug.Print oHttp.responseText

The response from the web page is in the .responseText property of the XMLHTTP object. How you process that is beyond me. I know that one of the Access newsgroup gurus has published a tutorial on consuming web services from Access, but I can t locate it. This article might have something to do with the issue:

http://support.microsoft.com/kb/285329/en-us

You can use the MARC21 XML from the Library of Congress.

I did the same thing as you, building a database to house my library. Scanning in the ISBN collects the data from this URL http://z3950.loc.gov:7090/voyager?version=1.1&operation=searchRetrieve&query=YOUR_ISBN&maximumRecords=1

The response data then fills in a form with all the data. You don t need an account, just that URL.

The response comes in XML (as mentioned), and you can parse from there using whatever language you want (my choice happens to be PHP).

The ISBNdb.com API looks simple. The following request should retrieve the information you want ... just substitute your access key for "YourKey" and the ISBN for "YourISBN".

https://isbndb.com/api/books.xml?access_key=YourKey&results=texts&index1=isbn&value1=YourISBN 

The response is XML which contains information about the single book whose ISBN you submitted.

What language are you using? You need a program/script to present a form where you can enter the ISBN, which would then get the data from isbndb.com and populate the database. I ve used the API a bit, but not for some time, and it s pretty straightforward.





相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签