问题描述
我在我的 android 应用程序中使用 SimpleXml 2.6.1.尽管文档 (http://simple.sourceforge.net/download/stream/doc/javadoc/index.html?org/simpleframework/xml/Order.html) 说 xml 中元素的顺序与方式相同它们已经在类文件中定义,我总是在 xml 中获得随机的顺序.如果我再添加几个变量,元素的顺序又会发生变化.
I am using SimpleXml 2.6.1 in my android app. Eventhough the documentation (http://simple.sourceforge.net/download/stream/doc/javadoc/index.html?org/simpleframework/xml/Order.html) says the order of the elements in the xml are same as the way they have defined in the class file, I am always getting the order to be random in the xml. If I add few more variables, the order of the elements again changes.
添加@Order 表示法有效,但由于该类很复杂,有 100 个变量,我不想添加顺序.这是 android 版本的已知错误吗?它在 java 控制台程序中运行良好.
Adding @Order notation works, but since the class is complex with 100s of variables, I do not want to add order. Is this a known bug for android versions? It works fine in java console programs.
ps:我打开反汇编的.class文件,发现变量声明的顺序和java文件一样,所以我不认为是class文件的问题.
p.s: I opened the .class file disassembled and found the variables declared in the same order as java file, so I don't think it's a class file issue.
推荐答案
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Order;
@Order(elements = {"name", "isTrue"})
public class SimpleXml {
public static final String NAME = "$NAME$";
public static final String IS_TRUE = "$IS_TRUE$";
@Element
private String name;
@Element
private Boolean isTrue;
...
这篇关于简单的 Xml - 不保留元素的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!