File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes XML to Object[] Utility Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML to Object[] Utility" Watch "XML to Object[] Utility" New topic
Author

XML to Object[] Utility

Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
I am new to XML.

I have to parse following XML code...

<task>
<export>
<title>List of Table</title>
<filename>TableList.csv</filename>
<query> select * from tab</query>
</export>

<export>
<title>List of Employee</title>
<filename>EmployeeList.csv</filename>
<query> select * from Employee</query>
</export>
</task>

I need above data in Object[], where each value of Object[] contains another Object[], that hold values of title, filename, query.

Can anybody provide me with the same code or utility?

Reg,
Chetan


My blood is tested +ve for Java.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Castor tool is probably what you want to look into for this.

Link1
Link2

- m


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 852
I am the author of the FormattedDataSet API. Primarily the API is used to get tabular data (result sets, collections, and Arrays) into text (xml, html, form letters etc). In working with tabular data I realized that most data is easy to get into an array (Object[][]), so over time I have come up with utilities that help manipulate arrays.

The link below is not in my api as it still needs some work, however it is pretty straightforward. Here is the link:

http://cvs.sourceforge.net/viewcvs.py/fdsapi/fdsapi/Examples/HTTPUtils/XMLToArrayConverter.java?rev=1.3&view=auto

Below is usage code, which is similar to the code in the main method in the above class. Feel free to take the class code and modify it to your needs.



http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
Hello I have developed following class for the same...



Create 1.xml file with following text in c:\.

[code]

<?xml version="1.0" encoding="UTF-8"?>

<FileList>
<file>
<filename>First</filename>
<title>First File</title>
<desc>1</desc>
<query>select * from tab</query>
</file>

<file>
<filename>2</filename>
<title>2</title>
<desc>2</desc>
<query>select * from tab2</query>
</file>
<file>
<filename>2342342</filename>
<title>3242</title>
<desc>drert</desc>
<query>erter6786</query>
</file>
</FileList>
[code]

Kindly give me feedback.

Reg,
Chetan
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by Chetan Parekh:
Hello I have developed following class for the same...
Kindly give me feedback.

Reg,
Chetan

Feedback on what?? You mean on your java code ??
Thanks
Balaji
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
About logic and code.
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 852
A more flexible solution would be to pass the parse method the xml as a String, and have separate code read in the file and put it in String format. I am not sure how big your xml files are. Obviously if they are huge then you may not be able to read them in as a String.
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
Thanks a lot!!

This is a good idea, specifically if you are accessing file from different server or you save xml in database or you are getting xml from other application via messaging service.

I will implement this thing.

Warm Regards,
Chetan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML to Object[] Utility
 
Similar Threads
Webspere 345 exam questions
Is this type of group by query possible in JPA ?
Export to excel
EJB3.0 persistence API
Struts2 + display tag