Reading XML data

Source: Internet
Author: User

Request.setcharacterencoding ("UTF-8");
String ISBN = Request.getparameter ("ISBN");
String uid = request.getparameter ("UID");
String Accesstoken = Request.getparameter ("Accesstoken");
Boolean flag = IsLogin (Accesstoken, UID);
if (!flag) {
mes = msgcode.mes_1004;
//}
Isbn= "9787121241536";//9787549501519
StringBuffer sb=new StringBuffer ();
Sb.append ("http://api.douban.com/book/subject/isbn/");
Sb.append (ISBN);
String result = this. Httpdoget (Sb.tostring ());
try {
Document Doc= (document) Documenthelper.parsetext (result);
Element books = Doc.getrootelement ();
SYSTEM.OUT.PRINTLN ("Root node" +books.getname ());
Iterator users_subelements = Books.elementiterator ("UID");//Specify to get that element
Iterator Elements = Books.elementiterator ();
while (Elements.hasnext ()) {
Element user = (Element) Elements.next ();
System.out.println ("Node" +user.getname () + "\ttext=" +user.gettext ());
Set objattrtofind=;
' Remove this node's attribute name, attribute value
String Nodeattrname=objattrtofind.nodename;
String Nodeattrvalue=objattrtofind.nodevalue;
Iterator txt = user.elementiterator ();
while (Txt.hasnext ()) {
Element usernext = (Element) Txt.next ();
System.out.println ("Node 2" +usernext.getname () + "\ttext2=" +usernext.gettext ());
}
List subelements = user.elements ();
List user_subelements = user.elements ("price");//Specify to get that element
System.out.println ("size==" +user_subelements.size ());
for (int i=0;i<user_subelements.size (); i++) {
Element ele = (Element) user_subelements.get (i);
System.out.print (Ele.getname () + ":" +ele.gettext () + "");
// }
System.out.println ();
}
} catch (Exception e) {
E.printstacktrace ();
}

Reading XML data

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.