Naing Win Htun Naing Win Htun - 1 year ago 127
Android Question

Android XMLSerializer cannot write all data into XML file

Now, I am trying to write XML file in running uiautomation test by uiautomator.
I used XMLSerializer for write XML in android. It is OK. It write XML file while running test. One thing that it cannot write all data as shown below.

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<desc>Test One</desc>
<desc>Test Two</desc>

See, it cannot write all data. Here my code.

// Export XML file content.
XmlSerializer serializer = Xml.newSerializer();

StringWriter stringWriter = new StringWriter();

serializer.startDocument("UTF-8", true);
serializer.setFeature("", true);

serializer.startTag(null, "tests");

for(Test test : testList){
serializer.startTag(null, "test");

serializer.startTag(null, "no");
serializer.endTag(null, "no");

serializer.startTag(null, "desc");
serializer.endTag(null, "desc");

serializer.endTag(null, "test");

serializer.endTag(null, "tests");

// Write file.
FileWriter fileWriter = new FileWriter("test.xml");



My testList has at least 15 test. So, it should write all tests. But it writes only 2. Why! I don't know.

Help me. Thanks.

Answer Source

I would prefer to use Editable in this case.


 Editable editable;
 editable.append("<Type> " + "Name"+ " </Type>" + "<Class>" +"Class Name" + "</Class>");

It's easier and does the same thing. Hope it helps. :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download