需要apache.xerces,自己去下
import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.SAXException;
import java.io.IOException;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.NamedNodeMap;public class DOMExample2{
 
    public static void main(String args[]) throws IOException, SAXException{
 
        DOMParser parser = new DOMParser();
        parser.parse("test.xml");
 
        Document dom = parser.getDocument();
 
        NodeList nlist= dom.getElementsByTagName("LOCAL ");
 
        for (int i=0;i<nlist.getLength();i++){
             Node aNode = nlist.item(i);
               System.out.println(aNode.getFirstChild().getNodeValue());
           
             NamedNodeMap attributes = aNodde.getAttributes();
 
             for (int a=0;a<attributes.getLength();a++){
             Node theAttribute = attributes.item(a);
             System.out.println(theAttribute.getNodeName() + " "+ theAttribute.getNodeValue());
               }
        }
 
            }}

解决方案 »

  1.   

    huataixiang19810225(无名) 
    对。
      

  2.   

    /LOCAL/@name好久没有用了,不知道对不对
      

  3.   

    不知道你用的是那种解析器,jdom,xerces,sax ?
      

  4.   

    我用的是jdom,请问放到jsp页面里行吗?谢谢哦
      

  5.   

    如果用jdom,可以这样取,没测试过,不知道对不对
    Document doc = sb.build(new FileInputStream(filePath));
    Element root = doc.getRootElement();
    String name=root.getAttributeValue("name");
      

  6.   

    你可以将XML解析作为一个类或EJB独立起来,需要解析的XML字符串作为输入,在JSP页面里调用这个封装好的模块。如果直接写到页面里面会有很多代码,这与asp又有什么区别?
      

  7.   

    谢谢huataixiang19810225,EA_FIFA() ,我搞定了!虽然flyoversky的方法不行,不过同样谢谢大家,小弟在次结贴散分咯!对了,小弟qq是183882759,希望能加我哦,我是刚入行的java程序员!