myeclipse中xml解析怎么做,就是开始-新建……那些了
发布网友
发布时间:2022-10-18 09:58
我来回答
共1个回答
热心网友
时间:2023-11-11 22:14
package org.lovo.xml;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
public class TestXml{
public String gjd;
public String zjd;
public String jdname;
public String content;
public TestXml(){
File file = new File("Test.xml");
SAXBuilder builder = new SAXBuilder();
try {
Document doc = builder.build(file);
Element root = doc.getRootElement();
gjd = root.getName();
Element stu = root.getChild("student");
zjd = stu.getName();
Element name = stu.getChild("name");
jdname = name.toString();
content = name.getName();
List<Element> list = root.getChildren();
for(int i=0;i<list.size();i++){
Element el = list.get(i);
System.out.println(el.getValue());
}
} catch (JDOMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args){
new TestXml();
}
}