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 閱讀(344) 評論(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


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


          網站導航:
           
          主站蜘蛛池模板: 长治市| 新沂市| 罗源县| 东乡族自治县| 陈巴尔虎旗| 淮北市| 隆尧县| 上杭县| 个旧市| 彰化县| 镶黄旗| 扎鲁特旗| 开原市| 大洼县| 肇源县| 广德县| 米易县| 贵溪市| 平湖市| 和硕县| 安西县| 邹平县| 望奎县| 渝中区| 石狮市| 红桥区| 金堂县| 定兴县| 京山县| 南京市| 双峰县| 且末县| 邵武市| 乌恰县| 潍坊市| 平塘县| 余庆县| 札达县| 宣汉县| 和田县| 阿克|