思路:
  1 用程序去访问 web service 服务.返回 xml文件。
  2 用dom 去解析xml
  3 用解析后的数据 生成 html文件

访问web service 的代码
Java代码
  1. public class StaticHTMLFile{  
  2.         public static boolean PrintPage(String page, String url_addr) {   
  3.             URL url;   
  4.             String rLine = null;   
  5.             PrintWriter fileOut = null;   
  6.             InputStream ins = null;   
  7.             File file=new File(page.trim());  
  8.               
  9.             try {   
  10.                 url = new URL(url_addr);   
  11.                 ins = url.openStream();   
  12.                 BufferedReader bReader = new BufferedReader(new InputStreamReader(ins,   
  13.                 "utf-8"));//获取编码为utf-8的文件   
  14.                 file.createNewFile();  
  15.                 FileOutputStream out = new FileOutputStream(file);   
  16.                 OutputStreamWriter writer = new OutputStreamWriter(out, "utf-8");   
  17.                 fileOut = new PrintWriter(writer);   
  18.                 //循环取取数据,并写入目标文件中   
  19.                 while ( (rLine = bReader.readLine()) != null) {   
  20.                 String tmp_rLine = rLine;   
  21.                 int str_len = tmp_rLine.length();   
  22.                 if (str_len > 0) {   
  23.                 fileOut.println(tmp_rLine);   
  24.                 fileOut.flush();   
  25.                  }   
  26.                 tmp_rLine = null;   
  27.                 }   
  28.                 url = null;   
  29.                 return true;  
  30.             } catch (IOException e) {   
  31.                 System.out.println("error: " + e.getMessage());   
  32.                 e.printStackTrace();   
  33.                 return false;   
  34.             } catch (Exception es) {   
  35.                 System.out.println(es.getMessage());   
  36.                 return false;   
  37.             }   
  38.             finally {//关闭资源   
  39.                 fileOut.close();   
  40.             try {   
  41.                 ins.close();   
  42.             } catch (IOException ex){   
  43.             //关闭输入流出错   
  44.                 ex.printStackTrace();  
  45.                 }   
  46.             }  
  47.           
  48.           
  49.         }  
  50.   
  51.       
  52.       
  53.     }  



把xml解析成int[]
Java代码
  1. public class DomXml2Int {  
  2.   
  3.     String fileName=null;//xml的文件  
  4.     String tagName=null;//要提取的xml中标签的名字  
  5.       
  6.       
  7.       
  8.       
  9.       
  10.     public String getFileName() {  
  11.         return fileName;  
  12.     }  
  13.   
  14.   
  15.   
  16.   
  17.     public void setFileName(String fileName) {  
  18.         this.fileName = fileName;  
  19.     }  
  20.   
  21.   
  22.   
  23.   
  24.     public String getTagName() {  
  25.         return tagName;  
  26.     }  
  27.   
  28.   
  29.   
  30.   
  31.     public void setTagName(String tagName) {  
  32.         this.tagName = tagName;  
  33.     }  
  34.   
  35.   
  36.   
  37.   
  38.       
  39.   
  40.   
  41.   
  42.   
  43.     public List<Integer> builder() throws ParserConfigurationException, SAXException, IOException{  
  44.           
  45.         List<Integer> ids=null;  
  46.                       ids=new ArrayList<Integer>();  
  47.           
  48.         DocumentBuilderFactory dbf=null;  
  49.         DocumentBuilder         db=null;  
  50.         Document                d=null;  
  51.         NodeList                nl=null;  
  52.         Node                    n=null;  
  53.                                 dbf=DocumentBuilderFactory.newInstance();  
  54.                                 db=dbf.newDocumentBuilder();  
  55.                                 d=db.parse(fileName);  
  56.                                 nl=d.getElementsByTagName(tagName);  
  57.         //循环取出每个Node的值  
  58.         for(int i=0;i<nl.getLength();i++){  
  59.             n=nl.item(i);//得到每个node  
  60.             //System.out.println(n.getTextContent());  
  61.             ids.add(Integer.valueOf(n.getTextContent()));  
  62.               
  63.         }  
  64.           
  65.           
  66.           
  67.           return ids;  
  68.     }  
  69.       
  70.       
  71.       
  72. }  



提取电视节目的代码

Java代码
  1. public class DomXml2String {  
  2.   
  3.     /** 
  4.      * @param args 
  5.      * @throws ParserConfigurationException  
  6.      * @throws IOException  
  7.      * @throws SAXException  
  8.      */  
  9.     public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {  
  10.           
  11.         System.out.println(new DomXml2String().builder("tt.xml")[0]);   
  12.         System.out.println(new DomXml2String().builder("tt.xml")[1]);   
  13.   
  14.            
  15.   
  16.           
  17.     }  
  18.       
  19.     //解析xml到数组中去  
  20.       
  21.      public String[] builder( String xmlFilePath ) throws ParserConfigurationException, SAXException, IOException{  
  22.          String[] tvShow= new String[2];  
  23.          StringBuffer tvShowTempAM=new StringBuffer();  
  24.          StringBuffer tvShowTempPM=new StringBuffer();  
  25.          DocumentBuilderFactory dbf=null;  
  26.            dbf=DocumentBuilderFactory.newInstance();  
  27.            DocumentBuilder db=null;  
  28.                db=dbf.newDocumentBuilder();  
  29.            Document d=null;  
  30.                   d=db.parse(new File(xmlFilePath));  
  31.            NodeList n=null;  
  32.                     n=d.getElementsByTagName("tvProgramTable");  
  33.            Node node=null;  
  34.            //循环得到每个节点的值  
  35.            for(int i=0;i<n.getLength();i++){  
  36.                 node=n.item(i);  
  37.                //System.out.println(i+node.getChildNodes().item(3).getTextContent() );  
  38.                if(node.getChildNodes().item(3).getTextContent().equals("AM")){  
  39.                       
  40.                 //System.out.println(i+" is am" );  
  41.                     tvShowTempAM.append(node.getChildNodes().item(1).getTextContent()+""+node.getChildNodes().item(5).getTextContent()+"<br>");  
  42.                       
  43.                       
  44.                 }else{  
  45.                //   System.out.println(i+" is pm" );  
  46.                       
  47.                     tvShowTempPM.append(node.getChildNodes().item(1).getTextContent()+""+node.getChildNodes().item(5).getTextContent()+"<br>");  
  48.                       
  49.                 }  
  50.                  
  51.            }  
  52.                 
  53.            
  54.          tvShow[0]="AM\n"+tvShowTempAM.toString();  
  55.          tvShow[1]="PM\n"+tvShowTempPM.toString();    
  56.            
  57.            
  58.            
  59.          return tvShow;  
  60.      }  
  61.       
  62.   
  63. }  


提取湖北省的所以电视节目
Java代码
  1. public class TVRequestWebServiceTest {  
  2.   
  3.     /** 
  4.      * @param args 
  5.      * @throws IOException  
  6.      * @throws SAXException  
  7.      * @throws ParserConfigurationException  
  8.      * @throws TemplateException  
  9.      */  
  10.     public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException, TemplateException {  
  11.           
  12.         List<Integer> dstIds=null;  
  13.                       
  14.                         
  15.         List<Integer> pdIds=null;  
  16.         String[] tvShow= new String[2];  
  17.         //根据省的id得到省的所有电视台的id(数据保存到dstIds.xml)  
  18.         StaticHTMLFile.PrintPage("E:/workspace/spring2Test/dstIds.xml",  
  19.                 "http://www.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx/getTVstationDataSet?theAreaID=17 "   
  20.                                                                                
  21.                   );  
  22.           
  23.           
  24.           
  25.         //根据dstIds.xml得到电视台的id(int)  
  26.         DomXml2Int dxi=null;  
  27.                    dxi=new DomXml2Int();  
  28.                    dxi.setFileName("dstIds.xml");  
  29.                   
  30.                    dxi.setTagName("tvStationID");  
  31.                    dstIds=dxi.builder();  
  32.         DomXml2String dx=null;  
  33.                dx=new DomXml2String();  
  34.         String2Html s2h=null;  
  35.           
  36.                      
  37.         //循环每个电视台得到每个电视的所以频道id  
  38.         for(int i=0;i<dstIds.size();i++){  
  39.       
  40.               
  41.             StaticHTMLFile.PrintPage("E:/workspace/spring2Test/pdIds" +  
  42.                     "_" +  
  43.                     dstIds.get(i) +  
  44.                     ".xml",  
  45.                     "http://www.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx/getTVchannelDataSet?theTVstationID=" +  
  46.                     dstIds.get(i)  
  47.                       );  
  48.             dxi.setFileName("pdIds_"+dstIds.get(i)+".xml");  
  49.             dxi.setTagName("tvChannelID");  
  50.             pdIds=dxi.builder();//获得每个电视台的所以频道id  
  51.             //测试  
  52.             /*for(int j=0;j<pdIds.size();j++){ 
  53.                 System.out.println(dstIds.get(i)+":"+pdIds.get(j)); 
  54.                  
  55.             } 
  56.             //测试成功 
  57.             */  
  58.             //循环每个频道得到频道的电视节目  
  59.             for(int j=0;j<pdIds.size();j++){  
  60.                   
  61.                 StaticHTMLFile.PrintPage("E:/workspace/spring2Test/pdIds" +  
  62.                         "_" +  
  63.                         dstIds.get(i)+  
  64.                         "_" +  
  65.                         pdIds.get(j)  
  66.                         +  
  67.                           
  68.                         ".xml",  
  69.                         "http://www.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx/getTVprogramDateSet?theTVchannelID=" +  
  70.                         pdIds.get(j)+  
  71.                         "&theDate=" +  
  72.                         "2009-02-20" +  
  73.                         "&userID="   
  74.                           
  75.                           );  
  76.             tvShow= dx.builder("pdIds_"+dstIds.get(i)+"_"+pdIds.get(j)+".xml");  
  77.             //测试 tvShow  
  78.             /*System.out.println(tvShow[0]); 
  79.             System.out.println(tvShow[1]); 
  80.              
  81.             *测试成功 
  82. AM 
  83. 07:00晨曲 
  84. 07:03重播:美嘉购物 
  85. 14:00重播:都市商报 
  86. 14:30重播:美嘉购物 
  87.  
  88. PM 
  89. 18:15元富财经 
  90. 18:37都市商报 
  91. 19:09股海罗盘 
  92. 19:30湖北新闻联播 
  93. 19:51天气预报 
  94. 19:55直播:美嘉购物 
  95. 23:55重播:美嘉购物 
  96. 02:00夜曲 
  97.  
  98.             * 
  99.             * 
  100.             */  
  101.               
  102.             //把tvshow的数据输出到html()  
  103.             s2h.builderHtml(tvShow, dstIds.get(i), pdIds.get(j));  
  104.               
  105.               
  106.               
  107.   
  108.             }  
  109.               
  110.               
  111.               
  112.               
  113.               
  114.         }        
  115.           
  116.                      
  117.   
  118.     }  
  119.   
  120. }  

把数据转换成html的代码
Java代码
  1. public class String2Html {  
  2.       
  3.     public static void builderHtml(String[] strS,int i,int j) throws IOException, TemplateException{  
  4.           
  5.         //初始化freeMarker  
  6.         File file=null;  
  7.              file=new File("E:\\workspace\\spring2Test\\htmlTest\\");  
  8.        Configuration cf=null;  
  9.                     cf=new Configuration();  
  10.                     cf.setDirectoryForTemplateLoading(file);  
  11.         Template template=null;   
  12.                  template=cf.getTemplate("tvShow.ftl");  
  13.         Map<String,String[]> root=null;  
  14.                              root=new HashMap<String,String[]>();  
  15.                     root.put("tvShow", strS);  
  16.         Writer out=null;  
  17.             //下面的文件名: 电视台id_频道id_时间.html    
  18.         out=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("E:/workspace/spring2Test/htmlTest/"+i+"_"+j+"_"+".html")),"utf-8"));  
  19.           
  20.         template.process(root, out);  
  21.           
  22.           
  23.           
  24.           
  25.           
  26.     }  
  27.   
  28. }  






//这里是原始的代码,需要好好整理整理。最好用soap