标签:
读取xml
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = builderFacotry.newDocumentBuilder();
Document document = builder.Parse(getAssets().open("lang.xml"));//在builder中传入xml位置
Element element = document.getDocumentElement();//根节点
NodeList list = element.getElementsByTagName("lan");
for(list){lan.getAttribute("id");lan.getElementByTagName("name").item(0).getTextContent();}
存xml
Document newxml = builder.newDocument();
Element languages = newxml.createElement("language");
languages.setAttribute("id",it);
Element lan1 = newxml.createElement("lan");
lan1.setAttibute("id","1");
Element name1 = newxml.createElement("name");
name1.setText(ontxt1,"Java");
lan1.appendChild(name1);
languages.appendChilde(lan1);
newxml.appendChild(language);
TransFormFactory transF = TrasFormFactory.newInstace();
Transformer trans = transF.newTransFormer();
trans.setOutputProperty("encoding","UTF-8");
trans.transform(new DoMSource(newXml),new StreamResult(OutputStreamWriter));
sw.toString();
标签:
原文地址:http://www.cnblogs.com/hzwcoming/p/4692749.html