I wrote This Code.It works great.But i have a trouble with its output string.
public static String CreateIndexForImage()
throws IllegalArgumentException, IllegalStateException, IOException
{
String Image_Name = "Bla BLa";
static XmlSerializer xmlSerializer = Xml.newSerializer();
static StringWriter writer = new StringWriter();
xmlSerializer.setOutput(writer);
xmlSerializer.startDocument("UTF-8", true);
xmlSerializer.startTag("", "imagefile");
xmlSerializer.startTag("", "image");
xmlSerializer.startTag("", "name");
xmlSerializer.text(Image_Name);
xmlSerializer.endTag("", "name");
xmlSerializer.endTag("", "image");
xmlSerializer.endTag("", "imagefile");
xmlSerializer.endDocument();
return writer.toString();
}
The output is like:
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><imagefile><image><name>Bla Bla</name></image></imagefile>
But i want the output ordered like this:
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<imagefile>
<image>
<name>Bla BLa</name>
</image>
</imagefile>
Is there a method or something to write like this in XmlSerializer class or StringWriter class? Otherwise i can do it another way to order the lines like above.
Have you tried something like that?
serializer.setProperty(
"http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " ");
serializer.setProperty(
"http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n");
I don't know if this still works. Otherwise you can try something like that:
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);