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


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


          網站導航:
           
          主站蜘蛛池模板: 通州市| 宝坻区| 新巴尔虎右旗| 鲁甸县| 囊谦县| 桐梓县| 博罗县| 寿阳县| 霍山县| 社旗县| 河池市| 册亨县| 图片| 泗阳县| 新丰县| 深泽县| 龙胜| 黑水县| 阿坝县| 兖州市| 寿宁县| 包头市| 瓮安县| 老河口市| 安远县| 嘉定区| 盐池县| 沂源县| 务川| 淄博市| 松桃| 宁化县| 本溪| 集安市| 宜州市| 绿春县| 军事| 星座| 海兴县| 靖州| 元朗区|