我正在做一个关于 html 文档操作的项目。我希望现有 html 文档中的正文内容将其修改为新的 html。现在我正在使用 JDOM。我想在我的编码中使用 body 元素。为此我在我的编码中使用了 getChild("body")。但是它返回 null 给我的程序。但是我的 html 文档有一个 body 元素。任何人都可以帮助我了解这个问题我是一名学生?
将不胜感激指针..
编码:
import org.jdom.Document;
import org.jdom.Element;
public static void getBody() {
SAXBuilder builder = new SAXBuilder("org.ccil.cowan.tagsoup.Parser", true);
org.jdom.Document jdomDocument=builder.build("http://www......com");
Element root = jdomDocument.getRootElement();
//It returns null
System.out.println(root.getChild("body"));
}
请也参考这些.. 我的 html 的根和子打印在控制台中...
root.getName():html
SIZE:2
[Element: <head [Namespace: http://www.w3.org/1999/xhtml]/>]
[Element: <body [Namespace: http://www.w3.org/1999/xhtml]/>]