[求助]DOM访问xml出了点问题!请那位大哥帮忙解决一下
package org.myxml.test;import
import
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.
System.out.println(db);
/这儿则输出:com.
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();
}
}
}
麻烦那位大侠帮忙解决一下啊`` 运行没有结果!!