我正在讀取SD卡上的xml文件。在這裏,我想改變的XML文件的值,我想將文件保存到SD卡..如何保存並更新xml文件中的值?
我的代碼如下....請指導我如何將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");
}
}
這也是類似的問題 –