代码:package org.gyj.xml.dom;
import java
import org.w3c.dom.*;
import javax.xml.parsers.*;
public class DOMDEMO
{
public static void main( String args[] ){
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance( );
DocumentBuilder build=factory.newDocumentBuilder();
Document doc=build.parse(new File("c:"+ File serparator +"DOM.xml"));
NodeList n1=new.getElementsByTagname("name");
System.out.println("姓名"+n1.item(0).getFirstchild().getNodevalue());
}
}
<?xml version="1.0" encoding="GBK" ?>
<addresslist>
<name>高玉杰</name>
</addresslist>
在EditPLUS中设计此程序,但是通过cmd运行、时找不到!!!!是怎么回事!真心请教!!
还是使用IDE吧,选择eclipse或myeclipse都可以的
NodeList n1=new.getElementsByTagname("name");
NodeList n1=doc.getElementsByTagname("name");吧