I have to write an XML file using java.The contents should be written from a map.The map contains items as key and their market share as value.I need to build an XML file withe two tags.I will use this XML to build a piechart using amcharts.Can anyone help with an existing code?
<xml>
<pie>
<slice title="<Map key1>"><Map Value1></slice>
<slice title="<Map key2>"><Map Value2></slice>
<slice title="<Map key1>"><Map Value3></slice>
.
.
.
<slice title="<Map keyn>"><Map Valuen></slice>
</pie>
There are a number of ways to do this using the standard API. (Insert your own caveats about verbosity and the factory pattern.)
You can use the XMLStreamWriter to encode the data:
Alternatively, you could build a DOM document (not recommended) and emit that, or use JAXB binding to marshal/unmarshal data (tutorial).
Sample annotated JAXB object:
Test code:
There are a host of third party APIs that can do the same jobs and various templating options have already been mentioned.