Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since there is no answer, I'll try to save precious time to anyone who gets here.</p> <p>I found no cause, and since I don't have time to analyze Simple libraries, I came up with a "workaroud". It's more of an advice, actually - don't use it for (marshaling)creating xml if you have a large xml definition and the order matters(a rule more than an exception). The order is mostly used for marshaling anyway so just save yourself some time and do it manually.</p> <p>The template:</p> <pre><code>&lt;document&gt; &lt;name&gt;$NAME$&lt;/name&gt; &lt;isTrue&gt;$IS_TRUE$&lt;/isTrue&gt; &lt;/document&gt; </code></pre> <p>The class:</p> <pre><code>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 */ /* &lt;dependency&gt; &lt;groupId&gt;org.apache.commons&lt;/groupId&gt; &lt;artifactId&gt;commons-io&lt;/artifactId&gt; &lt;version&gt;1.3.2&lt;/version&gt; &lt;/dependency&gt; */ final String stringTemplate = IOUtils.toString(templateStream); return stringTemplate; } } </code></pre> <p>The test:</p> <pre><code>import org.junit.Test; import static junit.framework.Assert.*; /** * User: ksaric */ public class SimpleXmlTest { @Test public void test() throws Exception { //Before /* Use standard instantiation, factory method recommended for immutability */ SimpleXml simpleXml = new SimpleXml(); simpleXml.setName("This is a name"); simpleXml.setTrue(false); //When String result = simpleXml.toString(); //Then assertNotNull(result); System.out.println(result); } } </code></pre> <p><strong>Not really an answer, but save yourself some time and don't use Simple(which is a great library) on Android...</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload