import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.IOException;
//jsoup解析xml的简单使用
public class JsoupDemo1 {
public static void main(String[] args) throws IOException {
//获取文件
String path = JsoupDemo1.class.getClassLoader().getResource("student.xml").getPath();
//获取dom对象
Document document = Jsoup.parse(new File(path),"utf-8");
//获取name
Elements name = document.getElementsByTag("name");
for (Element element : name) {
System.out.println(element.text());
}
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<students>
<student number="0001">
<name>tom</name>
<age>18</age>
<sex>male</sex>
</student>
<student number="0002">
<name id="mouse">jerry</name>
<age>18</age>
<sex>male</sex>
</student>
</students>
jsoup解析xml的简单使用