Let's go inside

          this blog is deprecated as a result of laziness.
          posts - 59, comments - 2, trackbacks - 0, articles - 0

          hello world jdom

          Posted on 2006-10-25 22:46 Earth 閱讀(337) 評論(0)  編輯  收藏 所屬分類: Eclipse

          8:00 - 9:00
          * 用swt開發一個窗口顯示hello world~(主要是學會搭建插件開發環境)


          9:00 - 10:00
          * 寫一個jdom的示例,功能:

          <books>
          ?<book name="java"><author>smart</author><price>2.00</price></book>
          ?<book name="c++"><author>kitten</author><price>4.00</price></book>
          <books>

          去掉其中的name屬性 和 <price>元素~

          555, 這是今天的作業。。完成了,貼出來,睡覺去~

          ?1 package ?jdom.test;
          ?2
          ?3 import ?java.io. * ;
          ?4 import ?java.util. * ;
          ?5
          ?6 import ?org.jdom. * ;
          ?7 import ?org.jdom.input. * ;
          ?8 import ?org.jdom.output.Format;
          ?9 import ?org.jdom.output.XMLOutputter;
          10
          11 public ? class ?HelloWorld? {
          12 ???? public ? static ? void ?main(String[]?args)? throws ?Exception? {
          13 ????????String?path? = ? " c:\\books.xml " ;
          14 ????????SAXBuilder?sb? = ? new ?SAXBuilder();
          15 ????????Document?doc? = ?sb.build( new ?FileInputStream(path));
          16 ????????Element?root? = ?doc.getRootElement();? // ?得到根元素
          17 ????????List?books? = ?root.getChildren();? // ?得到根元素所有子元素的集合
          18 ????????Element?book? = ? null ;
          19 ???????? for ?( int ?i? = ? 0 ;?i? < ?books.size();?i ++ )? {
          20 ????????????book? = ?(Element)?books.get(i);? // ?得到第一本書元素
          21 ????????????System.out.println(book.getAttributeValue( " name " ));
          22 ????????????book.removeAttribute( " name " );
          23 ????????????book.removeChild( " price " );
          24 ????????}

          25
          26 ????????Format?format? = ?Format.getPrettyFormat();
          27 ????????format.setIndent( " ?? " );
          28 ????????format.setEncoding( " utf-8 " );
          29 ????????XMLOutputter?outp? = ? new ?XMLOutputter(format);
          30 ????????FileOutputStream?fo? = ? new ?FileOutputStream(path);
          31 ????????outp.output(doc,?fo);
          32 ????}

          33 }

          34


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


          網站導航:
           
          主站蜘蛛池模板: 定陶县| 怀宁县| 金堂县| 宁陵县| 穆棱市| 梧州市| 门源| 馆陶县| 宜兰县| 闽清县| 阜新市| 图木舒克市| 衢州市| 阿拉善盟| 天长市| 房山区| 黄骅市| 潢川县| 即墨市| 阿拉善盟| 大英县| 山阳县| 富阳市| 镇原县| 廊坊市| 南平市| 拜城县| 涞水县| 锡林浩特市| 迭部县| 临猗县| 肇源县| 邹平县| 潮州市| 岑溪市| 内乡县| 榆树市| 鄂尔多斯市| 镇远县| 萨迦县| 禹城市|