由於沒有答案,我會盡力爲寶貴的時間來到這裏的任何人。
我找不到任何理由,因爲我沒有時間分析簡單的庫,所以我想出了一個「workaroud」。它實際上更多的是一種建議 - 如果你有一個很大的xml定義並且順序很重要(一個規則不止是一個例外),不要用它來創建xml(編組)。訂單主要用於編組,所以只需節省一些時間並手動完成。
模板:
<document>
<name>$NAME$</name>
<isTrue>$IS_TRUE$</isTrue>
</document>
類:
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.InputStream;
/**
* User: ksaric
*/
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();
}
/* GUAVA - checkNotNull() */
if (null == template) return null;
template = template.replace(NAME, getName());
/* OR CONVERT IN THE GETTER METHOD */
template = template.replace(IS_TRUE, getTrue().toString());
return template;
}
/* SINGLETON? Performance(IO) loss... */
public String getTemplate() throws IOException {
InputStream templateStream = getClass().getResourceAsStream("/template.xml");
/* APACHE IO COMMONS */
/*
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
*/
final String stringTemplate = IOUtils.toString(templateStream);
return stringTemplate;
}
}
測試:
不是一個真正的答案,但自己節省一些時間,不要使用簡單(這是一個偉大的圖書館)在Android上...
來源
2013-03-29 12:21:51
pfh
你有沒有發現任何解決方案或爲什麼Android應用程序不保存順序的原因?這可能是XPP android版本導致的嗎? – pfh
[我已經在這裏回答了這個問題](https://stackoverflow.com/a/48677998/3847464) –