大道致遠
          前途漫漫
          posts - 4,comments - 0,trackbacks - 0
          Document?doc? = ? null ;
          doc?
          = ?DocumentHelper.createDocument();
          // 添加根結點。
          Element?root? = ?doc.addElement( " root " );
          // 為根結點添加子結點。
          Element?child? = ?root.addElement( " child " );
          // 為節點添加屬性
          child.addAttribute( " childattribute " , " attribute " );
          // 為節點添加Text
          child.setText( " Text " );

          // 遍歷所有結點的方法

          Element?element?
          = ?doc.getRootElement();

          public ? void ?xmlIterator(Element?element)
          {
          ???????
          for ?( int ?i? = ? 0 ,?size? = ?element.nodeCount();?i? < ?size;?i ++ )????
          ????????
          {
          ???????????Node?node?
          = ?element.node(i);
          ???????????
          if ?(node? instanceof ?Element)?
          ????????????
          {
          ????????????????xmlIterator((Element)?node);
          ?????????????}
          ?
          ??????????}

          ??}


          // 如果想不遍歷而得到某一節點,那么就要為每一個節點添加一個ID屬性
          // 例如:Element.addAttribute("ID",id);
          // 然后用以下方法即可。
          Element?findElement? = ?doc.elementByID(id);
          posted on 2006-11-12 16:24 wyg405 閱讀(1365) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 通榆县| 庄浪县| 余庆县| 谷城县| 宜城市| 虞城县| 车致| 武宁县| 平罗县| 尚志市| 道孚县| 丰镇市| 确山县| 米林县| 晋中市| 嵊州市| 绩溪县| 德化县| 洪湖市| 浦城县| 鄄城县| 吴江市| 饶阳县| 慈溪市| 垦利县| 灵石县| 综艺| 新化县| 句容市| 和静县| 饶平县| 蛟河市| 龙里县| 定南县| 花莲县| 桦川县| 沂水县| 屯昌县| 安康市| 斗六市| 霸州市|