Foros de discusión

Export Custom Table data to XML

Mohamed Faisal, modificado hace 8 años.

Export Custom Table data to XML

Junior Member Mensajes: 90 Fecha de incorporación: 12/08/09 Mensajes recientes
Hi all,

I would like to export custom table data to XML file.
While clicking Export button, a XML file containing custom table data(custom_table1, custom_table2 etc ) exported is downloaded in the browser.

The samplle XML format is:
<custom_table1>
<column_name1></column_name1>
<column_name2></column_name2>
......
</custom_table1>
<custom_table2>
<column_name1></column_name1>
<column_name2></column_name2>
......
<custom_table2>


Please let me know how to do this functionality.

Thanks & Regards,
Faisal
thumbnail
David H Nebinger, modificado hace 8 años.

RE: Export Custom Table data to XML

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
How would you do it in a non-Liferay environment? Don't worry, it's a rhetorical question, I know the answer but am trying to figure out if you know it too.
Mohamed Faisal, modificado hace 8 años.

RE: Export Custom Table data to XML

Junior Member Mensajes: 90 Fecha de incorporación: 12/08/09 Mensajes recientes
Hi Nebinger,

I have not tried in non-Liferay environment. But we do it using DocumentBuilder, below is sample code

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("company");
doc.appendChild(rootElement);

then finally

StreamResult result = new StreamResult(new File("liferay.xml"));

I dont know that whether the above code will work or not?

Please let me know the answer.

Regards,
Faisal
thumbnail
Jan Geißler, modificado hace 8 años.

RE: Export Custom Table data to XML

Liferay Master Mensajes: 735 Fecha de incorporación: 5/07/11 Mensajes recientes
So if you don't mind me asking:
Why don't you try out before asking questions about things you haven't tried?
Mohamed Faisal, modificado hace 8 años.

RE: Export Custom Table data to XML

Junior Member Mensajes: 90 Fecha de incorporación: 12/08/09 Mensajes recientes
Hi Geißler,

Thank you for your suggestion. My question was that Is there any simple way using liferay API to achieve this?

Regards,
Faisal
thumbnail
David H Nebinger, modificado hace 8 años.

RE: Export Custom Table data to XML

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
Mohamed Faisal:
I have not tried in non-Liferay environment. But we do it using DocumentBuilder, below is sample code

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("company");
doc.appendChild(rootElement);

then finally

StreamResult result = new StreamResult(new File("liferay.xml"));


Well there's nothing magical about the portal. Do the same thing on the portal side, but you build into a Resource request handler to serve the XML content back to the browser.
Mohamed Faisal, modificado hace 8 años.

RE: Export Custom Table data to XML

Junior Member Mensajes: 90 Fecha de incorporación: 12/08/09 Mensajes recientes
Thank you Nebinger.
I have done the functionality with your suggestion, but I have one clarification :
I need to export total five tables data, there are 75 columns to export. For each and every column I need to write the following three lines of code.

Element serviceUrl = doc.createElement("test");
test.appendChild(doc.createTextNode(testValue));
configuration.appendChild(test);

Then the code will be too big. Please suggest the way to reduce the code.

Thanks & Regards,
Faisal
thumbnail
David H Nebinger, modificado hace 8 años.

RE: Export Custom Table data to XML

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
Mohamed Faisal:
I have done the functionality with your suggestion, but I have one clarification :
I need to export total five tables data, there are 75 columns to export. For each and every column I need to write the following three lines of code.

Element serviceUrl = doc.createElement("test");
test.appendChild(doc.createTextNode(testValue));
configuration.appendChild(test);

Then the code will be too big. Please suggest the way to reduce the code.


Personally I wouldn't be doing this at all. There's plenty of ORM and OXM tools to make this kind of thing possible.

But if you want to do it manually, reducing the code for the portal version is the same as reducing for the servlet version; if you can't reduce it there you won't be able to reduce it for the portal.
Mohamed Faisal, modificado hace 8 años.

RE: Export Custom Table data to XML

Junior Member Mensajes: 90 Fecha de incorporación: 12/08/09 Mensajes recientes
Hi Nebinger,

Thank you for your reply. I will check and do this.

Regards,
Faisal
Harsh Joshi, modificado hace 8 años.

RE: Export Custom Table data to XML

Junior Member Mensajes: 27 Fecha de incorporación: 28/01/15 Mensajes recientes
you can use Mule-ESB for esier access
thumbnail
David H Nebinger, modificado hace 8 años.

RE: Export Custom Table data to XML

Liferay Legend Mensajes: 14918 Fecha de incorporación: 2/09/06 Mensajes recientes
Mule ESB has nothing to do with OXM. It'd be like bringing a bag full of hammers to put a push pin into the wall.