dom4j將資料庫中的資料轉化為xml格式

2021-07-04 09:01:02 字數 1427 閱讀 6588

connection conn;

public connection connection() else

/*獲取引數*/

jdbc_driver = config.getproperty("jdbc_driver");

db_url = config.getproperty("db_url");

dbname = config.getproperty("dbname");

dbpasswd = config.getproperty("dbpasswd");

} catch (ioexception e)

try catch (sqlexception e) catch(classnotfoundexception e)

return conn;

}

public resultset query(string sql)  catch (sqlexception e) 

return rs;

}

/*

* sql:表示sql語句,要查詢的表資訊

* rootelementname:表示根節點的名稱

* eleelement:表示根節點下的第乙個子元素

* xmlname:表示要儲存的xml檔名

*/public

void

createxml(string sql, string rootelementname, string eleelement, string xmlname)

}writexml(doc, xmlname); //呼叫建立xml文件的方法,儲存為.xml格式

//將xml文件轉化為xml字串輸出

string documentstr = doc.asxml();

system.out.println("document 字串:");

system.out.println("+++++++++++++++++++++++++++++++++++");

system.out.println(documentstr);

system.out.println("+++++++++++++++++++++++++++++++++++");

}} catch (sqlexception e)

}

/*

*建立xml文件

*doc為讀取出來的document文字

*xmlname為要儲存的路徑

*/public

void

writexml(document doc, string xmlname) catch (ioexception e)

}

到此完成讀取和轉換(資料比較隨意).

DOM4J解析XML資料入庫

xml檔案內容格式 xml檔案為mysql資料庫匯出檔案 123jkh12jnejdasjk1223 張三18 男13767899999 123qweasdzxcrtyfgh456 李四18 女1896758976 123qweoirejnsdasd 王四18 男19089896666 示例 pub...

dom4j中xpath的使用

關鍵字 dom4j xpath 獲取document 查詢element xpath語法 xpath 使用路徑表示式在 xml 文件中選取節點。節點是通過沿著路徑或者 step 來選取的。表示式描述 nodename 選取此節點的所有子節點 從根節點擊取 從匹配選擇的當前節點擊擇文件中的節點,而不考...

dom4j中xpath的使用

獲取document 查詢element xpath語法 xpath 使用路徑表示式在 xml 文件中選取節點。節點是通過沿著路徑或者 step 來選取的。表示式 描述 nodename 選取此節點的所有子節點 從根節點擊取 從匹配選擇的當前節點擊擇文件中的節點,而不考慮它們的位置 選取當前節點 選...