<?xml version="1.0" encoding="utf-8"?>
<PDA >
<title title="PDA"></title>
<formid formid="0"></formid>
<first>
<title title="信息采集系统"></title>
<formid formid="01"></formid>
<tableName tableName="商品"></tableName>
<id id="1"></id>
<type type="name1"></type>
<name name="数据采集"></name>
</first>
<seconed>
<title title="用户信息"></title>
<formid formid="0101"></formid>
<tableName tableName="product"></tableName>
<id id="101"></id>
<type type="button1"></type>
<name name="取消"></name>
<fieldname fieldname=""></fieldname>
</seconed>
<seconed>
<title title="帐号管理"></title>
<formid formid="0102"></formid>
<tableName tableName="product"></tableName>
<id id="102"></id>
<type type="buttonno"></type>
<name name="确定"></name>
<fieldname fieldname=""></fieldname>
</seconed>
<first>
<title title="发布"></title>
<formid formid="02"></formid>
<tableName tableName=""></tableName>
<id id="2"></id>
<type type=""></type>
<name name="发布"></name>
</first>
<first>
<title title="二维码"></title>
<formid formid="03"></formid>
<tableName tableName=""></tableName>
<id id="3"></id>
<type type=""></type>
<name name="用户管理"></name>
</first>
<first>
<title title="04"></title>
<formid formid="04"></formid>
<tableName tableName=""></tableName>
<id id="4"></id>
<type type=""></type>
<name name="图片采集"></name>
</first>
</PDA>

解决方案 »

  1.   

    Lz题目不清楚,是所有的title属性呢,还是在first下的title属性呢
      

  2.   

    在网上查XQuery的资料,现在的JDK已经作为xml体系标准了你可以把XQuery想象成sql,把你的xml数据想象成数据库表数据
      

  3.   


    package com.ruihui.test;import java.io.FileInputStream;
    import java.io.IOException;import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;public class XmlParseTest {
    public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException {
    FileInputStream in=new FileInputStream("d:/test.xml"); SAXParserFactory spf=SAXParserFactory.newInstance();
    SAXParser parser=spf.newSAXParser();
    parser.parse(in, new MyHandler());
    in.close();
    }
    }class MyHandler extends DefaultHandler{
    private int space=0;

    @Override
    public void startElement(String uri, String localName, String qName,
    Attributes attributes) throws SAXException {
    for(int i=0;i<space;i++){
    System.out.print('\t');
    }
    System.out.println(qName+' '+attributes.getValue("title"));
    space ++;
    }
    @Override
    public void endElement(String uri, String localName, String qName)
    throws SAXException {
    space --;
    }
    }
      

  4.   

    你就用dom4j解析,只取title的值不就可以了
      

  5.   

    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import javax.xml.xpath.XPath;
    import javax.xml.xpath.XPathConstants;
    import javax.xml.xpath.XPathExpression;
    import javax.xml.xpath.XPathExpressionException;
    import javax.xml.xpath.XPathFactory;
    import org.w3c.dom.NodeList;
    import org.xml.sax.InputSource;public class Example {
        public static void main(final String[] args) {
            try {
                XPathFactory factory = XPathFactory.newInstance();
                XPath xpath = factory.newXPath();
                XPathExpression xpe = xpath.compile("//title/@title");
                NodeList nodes = (NodeList)xpe.evaluate(new InputSource(new FileReader("pda.xml")),XPathConstants.NODESET);
                for (int i = 0; i < nodes.getLength(); i++) {
                    System.out.println(nodes.item(i).getTextContent());
                }
            } catch (XPathExpressionException|FileNotFoundException e) {
                System.err.println(e.getMessage());
            }
        }
    }
    结果
    $java Example 
    PDA
    信息采集系统
    用户信息
    帐号管理
    发布
    二维码
    04
    $java -version
    java version "1.7.0"
    Java(TM) SE Runtime Environment (build 1.7.0-b147)
    Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode)