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


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


          網站導航:
           
          主站蜘蛛池模板: 抚顺市| 钦州市| 昌平区| 沙坪坝区| 平南县| 剑河县| 鞍山市| 莲花县| 罗城| 清涧县| 比如县| 封丘县| 衡山县| 锡林郭勒盟| 永州市| 灵石县| 合水县| 崇左市| 灵武市| 平原县| 兴义市| 巴彦县| 自贡市| 清水县| 博兴县| 隆安县| 巴里| 益阳市| 昌黎县| 兴国县| 获嘉县| 兰考县| 惠州市| 绵阳市| 罗江县| 连城县| 巴林左旗| 新河县| 威宁| 武穴市| 当阳市|