I have decided to create dynamic xml as a response of my rest service.
Xml structure is defined in properties file it may change in future.
What will best approach to achieve this task.
Help me out with suggestions friends.
Thanks in advance
I have decided to create dynamic xml as a response of my rest service.
Xml structure is defined in properties file it may change in future.
What will best approach to achieve this task.
Help me out with suggestions friends.
Thanks in advance
You can use the javax.xml.stream.XMLOutputFactory to generate the XML output. You can read the XML structure from the property file as your requirement and can generate the output using the javax.xml.stream.XMLOutputFactory.
Hope following code will helpful to you.
StringWriter stringWriter = new StringWriter();
XMLOutputFactory xmlFactory = XMLOutputFactory.newFactory();
XMLStreamWriter writer = xmlFactory.createXMLStreamWriter(stringWriter);
writer.writeStartDocument();
writer.writeStartElement(<<First element>>);
For Example
StringBuilder sb = new StringBuilder();
sb.append("<"+key+">");
sb.append("+value+");
sb.append("</"+key+">");
After this write it to a file . Using FileOutputStream.java