posts - 35,  comments - 7,  trackbacks - 0

          ?

          import ?java.io.FileOutputStream;
          import ?java.util.List;

          import ?org.jdom.Attribute;
          import ?org.jdom.Document;
          import ?org.jdom.Element;
          import ?org.jdom.input.SAXBuilder;
          import ?org.jdom.output.Format;
          import ?org.jdom.output.XMLOutputter;

          public ? class ?XML? {
          ????
          public ? static ? void ?main(String[]?args)? throws ?Exception? {

          ????????SAXBuilder?builder?
          = ? new ?SAXBuilder();
          ????????Document?doc?
          = ?builder.build( " d:\\destination.xml " );
          ????????Element?root?
          = ?doc.getRootElement();
          ????????root.removeChild(
          " Target " );
          ????????Element?items?
          = ?root.getChild( " Items " );
          ????????List?item?
          = ?items.getChildren( " item " );
          ????????
          for ?( int ?i? = ? 0 ;?i? < ?item.size();?i ++ )? {
          ????????????Element?elem?
          = ?(Element)?item.get(i);
          ????????????Attribute?attr?
          = ?elem.getAttribute( " displayName " );????????????
          ????????????attr.setValue(attr.getValue()?
          + ? " 中國 " );????????????
          ????????}

          ????????
          // ?保存
          ????????Format?format? = ?Format.getCompactFormat();
          ????????format.setEncoding(
          " gb2312 " );
          ????????format.setIndent(
          " ?? " );
          ????????XMLOutputter?XMLOut?
          = ? new ?XMLOutputter(format);
          ????????XMLOut.output(doc,?
          new ?FileOutputStream( " d:\\destination_tmp.xml " ));

          ????}

          }

          posted on 2006-05-13 09:22 java小記 閱讀(225) 評論(0)  編輯  收藏 所屬分類: 原創

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          <2006年5月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 阿拉善右旗| 屏东市| 定西市| 芦山县| 孟津县| 邳州市| 新宁县| 东宁县| 石河子市| 社旗县| 桑日县| 玉环县| 项城市| 阿荣旗| 瑞安市| 呼图壁县| 兴城市| 香港 | 马公市| 临沭县| 南华县| 松阳县| 桐柏县| 雷波县| 凯里市| 宁强县| 凌海市| 屏东县| 永兴县| 荆门市| 南靖县| 湛江市| 库尔勒市| 嘉定区| 昌吉市| 郓城县| 宣武区| 昭平县| 徐汇区| 德江县| 义乌市|