MDA/MDD/TDD/DDD/DDDDDDD
          posts - 536, comments - 111, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          dom4j用法

          Posted on 2009-10-25 18:43 leekiang 閱讀(453) 評論(0)  編輯  收藏 所屬分類: 文件處理
          ????String? xml="<?xml version=\"1.0\" encoding=\"GBK\" ?><root><test>0</test></root>";
          ?? 應該使用Document document = saxReader.read(new ByteArrayInputStream(xml.getBytes()));?
          如果使用Document?? document?? =?? saxReader.read(xml);會報no protocol 異常
          如果xml的encoding="utf-8",則xml.getBytes()要改為xml.getBytes("utf-8"),否則會報錯

          Element root=??document.getRootElement();
          得到root后取子元素,既可以
          Element e=root.element("test");
          也可以
          for (Iterator it = root.elementIterator(); it.hasNext();) {
          Element e = (Element) it.next();
          ??? String n = e.getName();
          ?? String v=e.getStringValue()
          }


          http://www.javatx.cn/clubPage.jsp?ccStyle=0&ccID=15&tID=1922
          http://lavasoft.blog.51cto.com/62575/66953
          主站蜘蛛池模板: 通海县| 甘泉县| 礼泉县| 武平县| 新邵县| 青田县| 东莞市| 隆尧县| 唐河县| 河西区| 公主岭市| 湘阴县| 资阳市| 惠来县| 弥勒县| 隆安县| 武城县| 镶黄旗| 鲜城| 原平市| 曲松县| 星座| 阆中市| 五大连池市| 天峨县| 崇明县| 靖边县| 双辽市| 玉门市| 肥城市| 扎鲁特旗| 贵南县| 蒙阴县| 江津市| 昌平区| 宁城县| 横峰县| 嘉禾县| 东安县| 钟山县| 平武县|