李敏  
          日歷
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345
          統計
          • 隨筆 - 1
          • 文章 - 40
          • 評論 - 4
          • 引用 - 0

          導航

          常用鏈接

          留言簿(1)

          文章分類

          文章檔案

          相冊

          收藏夾

          它山之石

          聚賢莊

          搜索

          •  

          最新評論

           
          XML(area.xml)
           
          <?xml version="1.0" encoding="GBK"?>

          <menu>
              
          <locations>
                  
          <site>北京</site>
                  
          <site>上海</site>
                  
          <site>重慶</site>
                  
          <site>浙江</site>
                  
          <site>廣東</site>
                  
          <site>湖北</site>
              
          </locations>
              
          <area location="北京" citysStr="東城區,西城區,海淀區,朝陽區" />

              
          <area location="上海" citysStr="黃浦區,徐匯區,長寧區,靜安區,普陀區,閘北區" />

              
          <area location="重慶" citysStr="渝中區,大渡口區,江北區,沙坪壩區,九龍坡區,南岸區" />

              
          <area location="浙江" citysStr="杭州市,寧波市,溫州市,嘉興市,湖州市,紹興市" />

              
          <area location="廣東" citysStr="廣州市,深圳市,珠海市,佛山市,東莞市" />

              
          <area location="湖北" citysStr="武漢市,黃石市,十堰市,荊州市,宜昌市,咸寧市" />
          </menu>

          Model

          Area.java
          package org.weibo.model;

          import java.util.ArrayList;
          import java.util.Arrays;
          import java.util.List;

          import org.weibo.lang.Strings;

          public class Area {
              
          private String location;

              
          private String citysStr;

              
          private List<String> citys = new ArrayList<String>();

              
          public List<String> getCitys() {
                  
          return citys;
              }


              
          public void setCitys() {
                  
          if (!Strings.isEmptyValue(citysStr)) {
                      String cityArray[] 
          = citysStr.split(",");

                      
          this.citys = Arrays.asList(cityArray);
                  }

              }


              
          public void setCitysStr(String citysStr) {
                  
          this.citysStr = citysStr;

                  setCitys();
              }


              
          public void setLocation(String location) {
                  
          this.location = location;
              }


              
          public String getLocation() {
                  
          return location;
              }


              
          public String getLocations() {
                  
          return location;
              }

          }

          TheAreaMenu.java
          package org.weibo.model;

          import java.util.ArrayList;
          import java.util.List;

          public class TheAreaMenu {
              
          private List<String> locations = new ArrayList<String>();

              
          private List<Area> areas = new ArrayList<Area>();

              
          public void addLocations(String location) {
                  locations.add(location);
              }


              
          public List<String> getLocations() {
                  
          return locations;
              }


              
          public void addAreas(Area area) {
                  areas.add(area);
              }


              
          public List<Area> getAreas() {
                  
          return areas;
              }

          }




          ApplicationCode

          try {

                      Digester digester 
          = new Digester();
                      digester.setValidating(
          false);

                      digester.addObjectCreate(
          "menu""org.weibo.model.TheAreaMenu");

                      digester.addCallMethod(
          "menu/locations/site""addLocations"1);
                      digester.addCallParam(
          "menu/locations/site"0);

                      
          // fdsafafafs0000
                      digester.addObjectCreate("menu/area""org.weibo.model.Area");
                      digester.addSetProperties(
          "menu/area");

                      digester.addSetNext(
          "menu/area""addAreas");

                      TheAreaMenu menu 
          = (TheAreaMenu) digester.parse(getClass()
                              .getResourceAsStream(
          "/areas.xml"));

                      List
          <String> locations = menu.getLocations();

                      
          for (String theLocation : locations) {
                          System.out.print(theLocation 
          + ",");
                      }

                      System.out.println();

                      List
          <Area> areas = menu.getAreas();

                      
          for (Area theArea : areas) {
                          System.out.print(theArea.getLocation() 
          + "=");

                          List
          <String> citys = theArea.getCitys();

                          
          for (String theCity : citys) {
                              System.out.print(theCity 
          + ",");
                          }

                          System.out.println();
                      }


                      
          // new InputStreamReader(getClass().getResourceAsStream(
                      
          // "/areas.properties"), "GBK");

                  }
           catch (IOException e) {
                      e.printStackTrace();
                  }
           catch (SAXException e) {
                      
          // TODO Auto-generated catch block
                      e.printStackTrace();
                  }

          posted on 2012-04-11 21:36 李敏 閱讀(330) 評論(0)  編輯  收藏 所屬分類: XML
           
          Copyright © 李敏 Powered by: 博客園 模板提供:滬江博客
          主站蜘蛛池模板: 肥东县| 德化县| 大新县| 湘乡市| 仙游县| 德钦县| 韩城市| 娱乐| 海阳市| 拉萨市| 武川县| 唐河县| 鄂伦春自治旗| 尉氏县| 钟祥市| 宜君县| 蕉岭县| 曲松县| 通许县| 南宫市| 兴安盟| 固阳县| 鸡泽县| 称多县| 普宁市| 林甸县| 长顺县| 临西县| 宜州市| 新平| 绥阳县| 东乌| 丘北县| 万全县| 清新县| 涪陵区| 西城区| 旌德县| 玉山县| 怀集县| 禹城市|