-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsoupDemo04.java
More file actions
42 lines (35 loc) · 1.31 KB
/
JsoupDemo04.java
File metadata and controls
42 lines (35 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package xml;
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;
/**
* @author : CodeWater
* @create :2022-03-11-14:26
* @Function Description :
* Element对象功能
*/
public class JsoupDemo04 {
public static void main(String[] args) throws IOException {
String path = JsoupDemo04.class.getClassLoader().getResource("xml/student.xml").getPath();
Document document = Jsoup.parse(new File(path), "utf-8");
Elements elements = document.getElementsByTag("name");
System.out.println(elements.size());
System.out.println("------------");
Element element_student = document.getElementsByTag("student").get(0);
Elements ele_name = element_student.getElementsByTag("name");
System.out.println(ele_name);
System.out.println(ele_name.size());
System.out.println("-----------------");
String number = element_student.attr("NUMBER");
System.out.println(number);
System.out.println("-----------------");
String text = ele_name.text();
String html = ele_name.html();
System.out.println(text);
System.out.println("-----------------");
System.out.println(html);
}
}