C # based on the Watercress API query book information

Source: Internet
Author: User
First, create a BookInfo class:
Class BookInfo
{
private string _name; public string Name
{
get {return _name;}
set {_name = value;}
}
private string _author; public string Author
{
get {return _author;}
set {_author = value;}
}
private string _imageurl; public string Imageurl
{
get {return _imageurl;}
set {_imageurl = value;}
}
private string _summary; public string Summary
{
get {return _summary;}
set {_summary = value;}
}
private string _ISBN; public string ISBN
{
get {return _ISBN;}
set {_ISBN = value;}
}
private string _pages; public string Pages
{
get {return _pages;}
set {_pages = value;}
}
private string _price; public string Price
{
get {return _price;}
set {_price = value;}
}
private string _publisher; public string Publisher
{
get {return _publisher;}
set {_publisher = value;}
}
Then invoke the BookInfo class in the main program:
HttpWebRequest myrequest = null;
HttpWebResponse myhttpresponse = null;
String doubanurl = "http://api.douban.com/book/subject/isbn/";
Doubanurl = Doubanurl + Textbox10.text + "?";
Myrequest = (HttpWebRequest) webrequest.create (Doubanurl);
Myhttpresponse = (HttpWebResponse) myrequest.getresponse ();
StreamReader reader = new StreamReader (Myhttpresponse.getresponsestream ());
String xmldetail = reader. ReadToEnd ();
Reader. Close ();
Myhttpresponse.close ();
BookInfo books = new BookInfo ();
XmlDocument xml = new XmlDocument ();
Xml. Loadxml (Xmldetail);
XmlNamespaceManager nsmgr = new XmlNamespaceManager (XML. NameTable);
Nsmgr. AddNamespace ("db", "Http://www.w3.org/2005/Atom");
XmlElement root = XML. DocumentElement;
XmlNodeList nodes = root. SelectNodes ("/db:entry", nsmgr);
foreach (XmlNode nodedata in nodes)
{
foreach (XmlNode childnode in Nodedata.childnodes)
{
String str = Childnode. Name;
Switch (STR)
{
Case "title":
Books. Name = Childnode. InnerText;
Break
Case "link":
if (Childnode. ATTRIBUTES[1]. Value = = "image")
{
Books. Imageurl = Childnode. Attributes[0]. Value;
}
Break
Case "Summary":
Books. Summary = Childnode. InnerText;
Break
Case "Db:attribute":
{
Switch (childnode. Attributes[0]. Value)
{
Case "Isbn13":
Books. ISBN = Childnode. InnerText;
Break
Case "Pages":
Books. Pages = Childnode. InnerText;
Break
Case "Author":
Books. Author = Childnode. InnerText;
Break
Case "Price":
Books. Price = Childnode. InnerText;
Break
Case "publisher":
Books. Publisher = Childnode. InnerText;
Break
Case "pubdate":
Books. pubdate = Childnode. InnerText;
Break
}//end switch
Break
}
}//end switch
}//end foreach
TextBox1.Text = "title:" + Books. Name;
TextBox2.Text = "Author:" + Books. Author;
TextBox3.Text = "Cover:" + books. Imageurl;
Textbox4.text = "ISBN:" + books. ISBN;
Textbox5.text = "Pages:" + books. Pages;
Textbox6.text = "Price:" + books. Price;
Textbox7.text = "Publishing house:" + books. Publisher;
Textbox8.text = "Published date:" + books. pubdate;
Textbox9.text = "Introduction:" + Books. Summary;
Picturebox1.waitonload = false;
Picturebox1.loadasync (books. Imageurl);//Use asynchronous load book cover photo

Back to write a Baidu music grab class, to rewrite the previous one, haha
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.