【发布时间】:2011-09-30 04:36:04
【问题描述】:
我正在从 SD 卡中读取一个 xml 文件。这里我想改变XML文件的值,我想把文件保存到sd卡..
我的代码如下......请指导我如何在更新值后将 XML 文件保存到 sd 卡......
public void modifyNodeval(){
try{
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(new File("/sdcard/sss.xml"));
//Get the staff element by tag name directly
Node nodes = doc.getElementsByTagName("Employee").item(0);
//loop the staff child node
NodeList list = nodes.getChildNodes();
for (int i =0; i<list.getLength();i++){
Node node = list.item(i);
//get the salary element, and update the value
if("Emp_Name".equals(node.getNodeName())){
node.setNodeValue("795796");
}
}
【问题讨论】: