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

          dom4j用法

          Posted on 2009-10-25 18:43 leekiang 閱讀(446) 評論(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
          主站蜘蛛池模板: 广丰县| 贡山| 元氏县| 庐江县| 运城市| 马山县| 朝阳县| 潮安县| 无极县| 东丰县| 南召县| 梓潼县| 那坡县| 酒泉市| 印江| 宜君县| 黎城县| 玛纳斯县| 浠水县| 繁昌县| 甘德县| 尼玛县| 台前县| 都昌县| 临江市| 尼木县| 从江县| 金华市| 砚山县| 阳信县| 襄垣县| 陆丰市| 文化| 岳阳县| 江华| 海伦市| 汉源县| 阿克陶县| 永春县| 济宁市| 屏边|