国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

使用JDOM操作XML系列文章三 平面式XML文件轉層疊式XML文件

2019-11-18 15:13:25
字體:
來源:轉載
供稿:網友

  使用JDOM操作xml系列文章三 平面式XML文件轉層疊式XML文件
package jing.xml;
/**
* <p>Title: 平面式XML文件轉層疊式XML文件</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author 歐朝敬 13873195792
* @version 1.0
*/
import org.jdom.*;
import org.jdom.output.*;
import org.jdom.input.*;
import org.jdom.XPath.*;
import java.io.*;
import java.util.*;

public class xmltotree {
public SAXBuilder sb = null;
public Document doc = null;
public Element root = null;
public xmltotree() throws Exception {
sb = new SAXBuilder(); // 新建立構造器
doc = sb.build(new FileInputStream("company.xml")); // 讀入文件
root = doc.getRootElement(); // 獲得根元素element

}

public void Listelemnet(String pid, Element element) throws Exception {
List find = XPath.selectNodes(root, "/ROOT/ROW[@PID=´" + pid + "´]");
int rowcount = find.size();
for (int i = 0; i < rowcount; i++) {
Element findelement = (Element) find.get(i);
Element element0 = new Element("ROW");
List attrib = findelement.getAttributes();
int j = attrib.size();
for (int h = 0; h < j; h++) {
Attribute attribute = (Attribute) attrib.get(h);
element0.setAttribute(
attribute.getName(),
attribute.getValue());

}
element.addContent(element0);
Listelemnet(findelement.getAttributeValue("CID"), element0);
}
}

public static void main(String[] args) throws Exception {
xmltotree bb = new xmltotree();

Element roote = new Element("ROOT");
Document tdocument = new Document(roote); //創建文檔ROOT元素

bb.Listelemnet("0", roote);

XMLOutputter outp = new XMLOutputter(Format.getPRettyFormat()); //格式華輸出,產生縮進和換行
Format format = outp.getFormat();
format.setEncoding("GB2312"); //設置語言
format.setExpandEmptyElements(true); //設置輸出空元素為<sample></sample>格式
outp.setFormat(format);
outp.output(tdocument, new FileOutputStream("companytree.xml")); //輸出XML文檔
//outp.output(tdocument,System.out);
System.out.print("XML 文檔生成完畢!");
}
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 嵊州市| 扶余县| 突泉县| 饶阳县| 安乡县| 兴安县| 松溪县| 措美县| 保德县| 板桥市| 长乐市| 瓮安县| 晋州市| 定州市| 深州市| 商水县| 海城市| 龙泉市| 安乡县| 郓城县| 神农架林区| 南澳县| 东明县| 贡觉县| 义马市| 五寨县| 江源县| 栖霞市| 宕昌县| 普洱| 北票市| 凤庆县| 聂荣县| 梓潼县| 镇雄县| 新兴县| 辽宁省| 武邑县| 五莲县| 沙湾县| 苏州市|