QQ QQ World country and region code get Java

Source: Internet
Author: User


Java with the tool class enough, download and install QQ, and then search the installation directory under the Loclist.xml file

Here is the code to parse the file, output as a bunch of SQL, you know, if you want the JSON object

Then change the Printnode.


Import javax.xml.parsers.documentbuilder;import javax.xml.parsers.documentbuilderfactory;import  org.w3c.dom.document;import org.w3c.dom.node;import org.w3c.dom.nodelist;public class  testxml {private static void printnode (Node n, node parent, int  level )  {parent = parent==null? n:parent; system.out.println ("insert  Into world_country (Id,name, pid, level) VALUES (  + n.getattributes () getNamedItem (" Code "). Getnodevalue () +", "+ " \ "" + n.getattributes (). getNamedItem ("Name"). Getnodevalue () + "\", "+ " \ "" + parent.getattributes (). getNamedItem ("Code"). Getnodevalue ()  + "\", "+ level +"); Public static void main (String[] args)  {         documentbuilderfactory dbf = documentbuilderfactory.newinstance ();         try&nBsp {            documentbuilder db =  Dbf.newdocumentbuilder ();             document  document = db.parse ("C:\\tmp\\loclist.xml");             nodelist l = document.getelementsbytagname ("CountryRegion");             system.out.println ("A total"  +  L.getlength ()  +  "countries");             for   (Int i = 0; i < l.getlength ();  i++)  {//State                  node n = l.item (i );                 printnode (N, null,1);                 nodelist childnodes =  N.getchildnodes ();                 for  (Int k = 0; k < childnodes.getlength ();  k++)  {                 node n2 =  childnodes.item (k);                 if ("state". Equals (N2.getnodename ())) {                  if (N2.getattributes (). getNamedItem ("Name") ==null) {                 nodelist childnodess =  n2.getchildnodes ();                 &nbsP;for (Int z = 0; z < childnodess.getlength ();  z++)  {                      Node ns = childnodess.item (z);                     if ("City". Equals (Ns.getnodename ())) { //                     &NBSP;SYSTEM.OUT.PRINTLN ("No state in this country");                     printnode (ns,n,3);                     }                     }                 continue;                  }                 printnode (n2,n,2);                 nodelist childnodes2 = n2.getchildnodes ();                 for (int u  = 0; u < childnodes2.getlength ();  u++)  {                 node n3 = childnodes2.item (U) ;                 if ("City"). Equals (N3.getnodename ())) {                  printnoDe (n3,n2,3);                 }                 }                 }                 }             }        } catch  ( Exception e)  {             E.printstacktrace ();         } }}



This article is from the "oracle+linux=>majesty" blog, make sure to keep this source http://majesty.blog.51cto.com/3493901/1933673

QQ QQ World country and region code get Java

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.