[求助]DOM访问xml出了点问题!请那位大哥帮忙解决一下
package org.myxml.test;import java.io.File;
import java.io.IOException;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import org.xml.sax.SAXException;
public class Test {
public static void main(String[] args) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
System.out.println(dbf);
//这儿输出:com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl@be2358
System.out.println(db);
/这儿则输出:com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl@1027b4d
File file = new File("student.xml");
Document doc = db.parse(file);
System.out.println(doc);
//这儿则输出:[#document: null]
NodeList nl = doc.getElementsByTagName("sutdent");
int len = nl.getLength();
for(int i=0; i < len; i++){
Element eltStu = (Element)nl.item(i);
Node eltName = eltStu.getElementsByTagName("name").item(0);
Node eltSex = eltStu.getElementsByTagName("Sex").item(0);
String name = eltName.getFirstChild().getNodeValue();
String sex = eltSex.getFirstChild().getNodeValue();
System.out.print("姓名:");
System.out.println(name);
System.out.print("性别:");
System.out.println(sex);
}
}
catch(ParserConfigurationException e) {
e.printStackTrace();
}
catch(SAXException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}
}
}
麻烦那位大侠帮忙解决一下啊`` 运行没有结果!!
搜索更多相关主题的帖子:
DOM xml import dbf org
----------------解决方案--------------------------------------------------------
没有人吗`?
为什么Document doc = db.parse(file);这儿解析为XML时``反回是的空啊`
查了很我资料啊`` 都是这样的` 不明白啊```
----------------解决方案--------------------------------------------------------