我的xml看起来像这样
<?xml version="1.0"?>
<config>
<string name="string1">anything</string>
<string name="string2">anything</string>
<boolean name="bool1" value="true" />
<boolean name="bool2" value="true" />
<long name="long1" value="1444444444" />
<long name="long2" value="1444444444" />
<long name="long3" value="1444444444" />
</config>
我正在使用nodeList
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(new File("filelocation"));
NodeList nodeList = document.getElementsByTagName("string");
for(int x=0,size= nodeList.getLength(); x<size; x++) {
String sssss = nodeList.item(x).getAttributes().getNamedItem("name").getNodeValue();
if (sssss.equals("string2")){
Node node = nodeList.item(x);
node.getParentNode().removeChild(node);
// i get here i need to remove string 2 and set some value of string 1 and long1 how can i do it ?
}
}
} catch (Exception e) {
e.printStackTrace();
}
因此应删除string2并编辑long1和string 1的值 所以删除字符串2不起作用