File newxmlfile = new File("/data/com.itwine/emergency.xml");
try{
newxmlfile.createNewFile();
}catch(IOException e){
Log.e("IOException", "exception in createNewFile() method");
}
//we have to bind the new file with a FileOutputStream
FileOutputStream fileos = null;
try{
fileos = new FileOutputStream(newxmlfile);
}catch(FileNotFoundException e){
Log.e("FileNotFoundException", "can't create FileOutputStream");
}
//we create a XmlSerializer in order to write xml data
XmlSerializer serializer = Xml.newSerializer();
try {
//we set the FileOutputStream as output for the serializer, using UTF-8 encoding
serializer.setOutput(fileos, "UTF-8");
//Write <?xml declaration with encoding (if encoding not null) and standalone flag (if standalone not null)
serializer.startDocument(null, Boolean.valueOf(true));
//set indentation option
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
//start a tag called "root"
serializer.startTag(null, "root");
*//**serializer.startTag(null, "Child1");
serializer.endTag(null, "Child1");
serializer.startTag(null, "Child2");
serializer.attribute(null, "attribute", "value");
serializer.endTag(null, "Child2");*//*
serializer.startTag(null, "EmailId");
serializer.text(txtemailid.getText().toString());
serializer.endTag(null,"EmailId");
serializer.startTag(null, "PhoneNo");
serializer.text(txtphoneno.getText().toString());
serializer.endTag(null,"PhoneNo");
serializer.endTag(null,"root");
serializer.endDocument();
//write xml data into the FileOutputStream
serializer.flush();
//finally we close the file stream
fileos.close();
Toast.makeText(getApplication(), "xml created",Toast.LENGTH_LONG);
} catch (Exception e) {
Log.e("Exception","error occurred while creating xml file");
}
예 way.You가 XMLserializer.Take에게 내가 예를 준 모양을 사용하여 속성과 태그를 설정 Xmlfile.and를 작성하는 FileOutputStream에 사용할 수있다.
음, xml을 만드는 것은 다소 단순합니다. 모든 상태 노드는 여러 도시 노드를 갖습니다. 각 도시 노드는 여러 정보 노드 등을 가질 것입니다. 큰 xml 파일이 갈 길인지 아닌지 궁금해합니다. '조회'를 수행하는 속도가 느리거나 모든 것을 메모리에 보관하는 데 비용이 많이 듭니다. 아마도 콘텐츠 용 데이터베이스를 사용하는 것이 좋습니다. –
html 파일의 크기는 약 56.3KB입니다. 따라서 파싱하는 동안 속도가 느려 집니까? 이제 XML 파일을 구문 분석하고 정보를 추출하는 방법은 무엇입니까? 혀를 향한 링크? 대부분의 사람들은 내가하는 일이 아닌 웹 사이트에 연결하여 보여줍니다. – Questions
최종 xml 구조의 복잡성, 파서 (SAX vs. DOM) 및 사용중인 장치에 따라 다르므로 말하기는 어렵습니다. SimpleXML이나 잭슨 매퍼 같은 것을 사용하는 것은 당신 쪽에서 최소한의 파싱 노력이 필요할 것입니다. 실제 구문 분석 논리를 설명하고 배경 스레드에 힘든 작업을 위임하는 한 모든 자습서에서 수행 할 것이라고 말하고 싶습니다. xml 내용의 출처는 오히려 관련성이 없어야합니다. –