Since there is no answer, I will try to save valuable time to everyone who gets here.
I did not find a reason, and since I don’t have time to analyze simple libraries, I came up with "workaroud". Actually this is more advice, do not use it for (marshaling) xml creation if you have a large xml definition and order (rule is more than an exception). An order is mainly used for marshaling, so just save time and do it manually.
Template:
<document>
<name>$NAME$</name>
<isTrue>$IS_TRUE$</isTrue>
</document>
Grade:
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.InputStream;
public class SimpleXml {
public static final String NAME = "$NAME$";
public static final String IS_TRUE = "$IS_TRUE$";
private String name;
private Boolean isTrue;
public SimpleXml() {
}
public Boolean getTrue() {
return isTrue;
}
public void setTrue(Boolean aTrue) {
isTrue = aTrue;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
String template = null;
try {
template = getTemplate();
} catch (IOException e) {
e.printStackTrace();
}
if (null == template) return null;
template = template.replace(NAME, getName());
template = template.replace(IS_TRUE, getTrue().toString());
return template;
}
public String getTemplate() throws IOException {
InputStream templateStream = getClass().getResourceAsStream("/template.xml");
final String stringTemplate = IOUtils.toString(templateStream);
return stringTemplate;
}
}
Test:
import org.junit.Test;
import static junit.framework.Assert.*;
public class SimpleXmlTest {
@Test
public void test() throws Exception {
SimpleXml simpleXml = new SimpleXml();
simpleXml.setName("This is a name");
simpleXml.setTrue(false);
String result = simpleXml.toString();
assertNotNull(result);
System.out.println(result);
}
}
, Simple ( ) Android...