I wrote a question that has not had much success: https://stackoverflow.com/questions/21296465/serialize-hashmap-as-xml-without-repeating-parent-elements. It occurs to me that perhaps I was asking the wrong question.
Is there a built-in Android class for creating XML non-continuously?
By non-continuously, I mean able to manipulate existing elements (add/remove children, etc). So far, I've found methods of creating XML (XmlSerializer, building Strings), but only in a continuous document.
Here is the pseudocode for what I am looking for:
[...]
//Note: Element is not a real class, but I'm guessing there will need to be a class that handles adding/removing other attributes, values, and other Elements.
//add necessary header for XML
xmldoc.startXML();
// this creates and returns an Element representing "<object></object>"
Element rootNode = xmldoc.addElement("object", "");
//this inserts "<key>key1</key>" into "<object></object>" and returns itself
Element key1 = rootNode.addChildElement("key", "key1");
//this inserts "<value>value1</value>" into "<object></object>" but I don't care about setting it as a variable for later use.
rootNode.addChildElement("value", "value1");
[...]
//write the XML as a String/Stream/Something (called handler here).
xmldoc.flush(handler);
With some additional logic those functions could create the following XML
<object>
<key>root</key>
<object>
<key>key1</key>
<value>value1</value>
</object>
<object>
<key>key2</key>
<value>value2</value>
</object>
<object>
<key>ns</key>
<object>
<key>key3</key>
<value>value3</value>
</object>
<object>
<key>key4</key>
<value>value4</value>
</object>
</object>
</object>