留言板

Export Custom Table data to XML

Mohamed Faisal,修改在8 年前。

Export Custom Table data to XML

Junior Member 帖子: 90 加入日期: 09-8-12 最近的帖子
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,修改在8 年前。

RE: Export Custom Table data to XML

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
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,修改在8 年前。

RE: Export Custom Table data to XML

Junior Member 帖子: 90 加入日期: 09-8-12 最近的帖子
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,修改在8 年前。

RE: Export Custom Table data to XML

Liferay Master 帖子: 735 加入日期: 11-7-5 最近的帖子
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,修改在8 年前。

RE: Export Custom Table data to XML

Junior Member 帖子: 90 加入日期: 09-8-12 最近的帖子
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,修改在8 年前。

RE: Export Custom Table data to XML

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
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,修改在8 年前。

RE: Export Custom Table data to XML

Junior Member 帖子: 90 加入日期: 09-8-12 最近的帖子
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,修改在8 年前。

RE: Export Custom Table data to XML

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
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,修改在8 年前。

RE: Export Custom Table data to XML

Junior Member 帖子: 90 加入日期: 09-8-12 最近的帖子
Hi Nebinger,

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

Regards,
Faisal
Harsh Joshi,修改在8 年前。

RE: Export Custom Table data to XML

Junior Member 帖子: 27 加入日期: 15-1-28 最近的帖子
you can use Mule-ESB for esier access
thumbnail
David H Nebinger,修改在8 年前。

RE: Export Custom Table data to XML

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
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.