大道致遠
          前途漫漫
          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 閱讀(1367) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 兴安县| 大城县| 大港区| 平湖市| 阜宁县| 香港 | 通江县| 鲁山县| 连南| 孙吴县| 鄯善县| 正蓝旗| 大邑县| 灵武市| 湖口县| 全州县| 米林县| 建水县| 孟连| 平谷区| 南皮县| 太和县| 宁津县| 开化县| 南昌市| 交城县| 扬中市| 大丰市| 紫阳县| 民勤县| 岗巴县| 怀宁县| 喀喇沁旗| 易门县| 将乐县| 孝义市| 乡城县| 大名县| 唐河县| 大关县| 巩留县|