Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I convert data in a specific format to XML using Java?

Posted on 2011-02-15
7
Medium Priority
?
309 Views
Last Modified: 2012-08-14
Hi,
I have some data in a file in a specific format. A sample of the same is given below. I need to convert this data to XML

{ "tag1": "46709" ,"tag2" : "Tom" ,"tag3" : "John" ,"tag4" : "501.1" ,"tag5" : "USD 941.70" ,"tag6": "0" ,"tag7":"3:59PM MST" ,"tag8" : "Feb 15, 3:59PM MST" ,"tag9" : "-31.75" ,"tag10" : "3.49" ,"tag11" : "abc" } ,{ "tag1": "20437" ,"tag2" : "dave" ,"tag3" : "matt" ,"tag4" : "5,481.00" ,"tag5" : "USD 5,481.00" ,"tag6": "0" ,"tag7":"4:27PM MST" ,"tag8" : "Feb 15, 4:27PM MST" ,"tag9" : "+171.00" ,"tag10" : "3.22" ,"tag11" : "chg" }

In the above data, I've copied two rows. The two rows are separated by curly brackets and a comma (} ,{). Also, the tag and the value are separated by a colon (:). I could simply insert this data in a database but in my situation there's a possibility that an additional tag could get added in this data. Hence my thought of using XML as a tag.

I'll be using Java for my application. Any help with the same would be appreciated.

Thanks.
0
Comment
Question by:orazen12
  • 3
  • 3
7 Comments
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34897638
So you just want to replace anything in the form of "x":"y" to <x>y</x>?
Then maybe {tagsandvalues} to <record>tagsandvalues</record>?
0
 
LVL 16

Accepted Solution

by:
Swapnil Piparia earned 2000 total points
ID: 34897664
Hi orazen12,

The format that you specified is JSON. Below article has step by step solution to convert JSON to XML in Java.

http://answers.oreilly.com/topic/279-how-to-convert-json-to-xml-in-java/

Thanks,
netswap
0
 

Author Comment

by:orazen12
ID: 34898295
Thanks netswap.
One more question, how do I add the dependency. I did a lot of Google search but could not find that.
 
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Expert Comment

by:Swapnil Piparia
ID: 34898522
Hi orazen12,

      The method depend on which tool you are using for development.

      1. Using eclipse
           http://www.avajava.com/tutorials/lessons/how-do-i-add-a-project-as-a-dependency-of-another-project.html
       2. Websphere
           http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r1m0/index.jsp?topic=/com.ibm.etools.mft.doc/ac30280_.htm

        More info : http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

        Hope this will help.

Thanks,
netswap
0
 

Author Comment

by:orazen12
ID: 34940814
netswap,
Thanks for the links and sorry for the delay in reply as I had been travelling. I'll check the links and get back to you.

Thanks.
0
 

Author Comment

by:orazen12
ID: 34942920
netswap,
I'm having trouble using Maven. I've installed it on my computer and have downloaded a sample project. I'm trying to use Maven with Eclipse but am not able to. I googled and found another way to do it. The url www.json.org/java/ has the class files for the conversion. I downloaded that and wrote a small program to convert it.

Though I've found the solution, I'd still like to know if I have to use Maven if I take the approach suggested by you or can it be done without Maven too?

Thanks.
0
 
LVL 16

Expert Comment

by:Swapnil Piparia
ID: 34943527
Hi orazen12,

       I haven't try without maven. So not sure about it.

       this might help you : http://www.mkyong.com/maven/maven-dependency-libraries-not-deploy-in-eclipse-ide/ with maven problem.


Thanks,
Netswap.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question