I have an android application which I am trying to change a node value.
Below I can take xml file from assets folder and get the specific node I want.
InputStream in_s = getApplicationContext().getAssets().open("platform.xml");
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = (Document) docBuilder.parse(in_s);
Node path = doc.getElementsByTagName("path").item(0);
path.setNodeValue(txtPath.getText().toString());
But when it comes to transform I stuck.
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer trans = transFactory.newTransformer();
trans.setOutputProperty(OutputKeys.INDENT, "yes");
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult("platform.xml");
//there should be something to write to xml file in assets.. I just cant figure it out..
trans.transform(source, result);
You can't write/update files in assets folder. You need to copy the xml file from assets to sdcard and then modify it.
Copy xml to sdcard:
Permission in manifest: