做过。但是数据太多了不行,少还可以。
数据多就把一个大xml切成多个小xml

解决方案 »

  1.   

    <?xml version="1.0" encoding="UTF-8"?><database>
    <ServerName>myLocalHost</ServerName>
    <DatabaseName>myDatabaseName</DatabaseName>
    </database>
    package com.myproject.test;import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;import org.w3c.dom.Document;
    import org.w3c.dom.NodeList;public class ReadDatabase {
    public static String serverName; public static String databaseName; public static String userName; public static String password; public static void readDatabase1() { DocumentBuilderFactory theDocumentBuilderFactory = DocumentBuilderFactory
    .newInstance();
    String path = "D:\\Projects\\myproject\\src\\com\\myproject\\test\\database.xml";
    try {
    DocumentBuilder theDocumentBuilder = theDocumentBuilderFactory
    .newDocumentBuilder();
    Document theDocument = theDocumentBuilder.parse(path);
    theDocument.getDocumentElement(); NodeList nodelist; nodelist = theDocument.getElementsByTagName("ServerName");
    if (nodelist.getLength() > 0) {
    serverName = (nodelist.item(0)).getFirstChild().getNodeValue();
    System.out.println(nodelist.item(0).getNodeName() + "="
    + serverName);
    } nodelist = theDocument.getElementsByTagName("DatabaseName");
    if (nodelist.getLength() > 0) {
    databaseName = (nodelist.item(0)).getFirstChild()
    .getNodeValue();
    System.out.println(nodelist.item(0).getNodeName() + "="
    + databaseName);
    } nodelist = theDocument.getElementsByTagName("UserName");
    if (nodelist.getLength() > 0) {
    userName = (nodelist.item(0)).getFirstChild().getNodeValue();
    System.out.println(nodelist.item(0).getNodeName() + "="
    + userName);
    } nodelist = theDocument.getElementsByTagName("Password");
    if (nodelist.getLength() > 0) {
    password = (nodelist.item(0)).getFirstChild().getNodeValue();
    System.out.println(nodelist.item(0).getNodeName() + "="
    + password);
    } } catch (Exception e) {
    e.printStackTrace();
    } } public static void main(String args[]) {
    readDatabase1();
    }}
      

  2.   

    我所说的不是这个 是一个完整的程序可是对xml进行增删改查,最好还支持模糊查询