views:

190

answers:

2

I need to get book information from isbndb.com trough XML service using this link http://isbndb.com/api/books.xml?access_key=12345678&index1=isbn&value1=9780321635345.

Any Idea how to do that in delphi?

+3  A: 

You need a HTTP client (lets say Indy) and an XML parser. For XML parser just use OmniXML for instance. Indy is included with Delphi7. Then just write a code like this:

procedure TForm1.Button1Click(Sender: TObject);
const
  cURL = 'http://isbndb.com/api/books.xml?access_key=12345678&index1=isbn&value1=9780321635345';
var
  HTTPClient: TIdHTTP;
  XMLAsStream: TMemoryStream;
  XMLDocument: IXMLDocument;
begin
  HTTPClient := TIdHTTP.Create(nil);
  try
    XMLAsStream := TMemoryStream;
    try
      HTTPClient.Get(cURL, XMLAsStream);
      XMLAsStream.Position := 0; 

      XMLDocument := CreateXMLDoc;
      XMLDocument.LoadFromStream(XMLAsStream);
    finally
      XMLAsStream.Free;
    end;
  finally
    HTTPClient.Free;
  end;
end;

Now you have your XML document parsed as DOM in memory. Just use it :)

Runner
And instead of OmniXML you can use TXMLDocument that comes standard with Delphi 7 as well.
Lars Truijens
Sure, I just made an example with the parser I use :)
Runner
+2  A: 

Which Delphi 7 edition do you have?

The Delphi 7 Feature Matrix indicates that if you have Delphi 7 Enterprise or Architect, you can use the built-in XML Data Binding Wizard for generating Delphi classes around your XML. Those classes are wrappers around the XML DOM. They make working with the XML a lot easier.

See this answer and this video on some how to use the XML Data Binding Wizard.

Getting the XML is easiest by using Indy like Runner mentioned.

If you have Delphi 7 Standard or Professional, then you don't have the XML Data Binding Wizard, so you will have to parse the XML with an XML DOM.

Note there an XML DOM can cover more or less from the standardized Level 1, Level 2 or Level 2.
Your XML determines which level you need.

I'm not completely sure if Delphi 7 Standard and Professional includes an XML DOM, but there are various XML DOMs available for Delphi 7.
A lot of people use the MSXML DOM (which supports Level 2 and is available on most Windows systems as it is included with Internet Explorer and many other pieces of Microsoft software).
An open source implementation XML DOM is OmniXML (which Runner also pointed out; note it supports Level 1 only).

--jeroen

Jeroen Pluimers