java 处理xml

 

	
package com.thd.test;
import java.io.IOException;
import java.util.List;
import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
public class T01 {
	public static void main(String args[]){
		SAXBuilder builder = new SAXBuilder();
		try {
			Document doc = builder.build("bin/tec.xml");
			Element root = doc.getRootElement();
			List<Element> c = root.getChildren("rs");
			for(Element rs : c){
				Attribute attr = rs.getAttribute("id");
				Element tit = rs.getChild("title");
				System.out.println(tit.getText());
				System.out.println(attr.getValue());
			}
			System.out.println("success");
		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

	

 

 

你可能感兴趣的:(java,C++,c,xml,C#)