Solved

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

Posted on 2011-02-15
7
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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
Technology Partners: 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!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The greatest common divisor (gcd) of two positive integers is their largest common divisor. Let's consider two numbers 12 and 20. The divisors of 12 are 1, 2, 3, 4, 6, 12 The divisors of 20 are 1, 2, 4, 5, 10 20 The highest number among the c…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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