2 Replies - 912 Views - Last Post: 26 February 2013 - 12:10 PM

#1 nullcoding  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 99
  • Joined: 08-July 12

Simplest way to utilize XML?

Posted 25 February 2013 - 05:03 PM

Hello!

I am working on a program that relies on data pulled from an online database that is regularly updated by its owners and operators. This data changes on a daily basis, but to the best of my knowledge,there is only an update once per day.

Thing is, the program I'm writing absolutely must be able to retrieve and store this data in a program-friendly format. I am currently writing the program in Java, although I could easily translate it. The database has its own API that allows me to retrieve the data as a JSON, and I have a way of reading that in Java, just as it can be read in many other languages. I was thinking about using XML for the application to store its own data, though, because I'm more familiar with it. I'm just not a hundred percent sure how to best automate the process!

It's also worth mentioning that currently our dataset is stored in a Google spreadsheet, which I can retrieve as XML, JSON, CSV, and so on...

Say I wanted to write a script that would simply retrieve the JSON object and parse it into an existing XML which would in turn be read by my program. The script should be run from the program itself. Now, I have a vague idea of how to do so in Java, and I know how to read/write XML in Java in a basic fashion. I've heard that PHP or even Javascript might actually be better suited to this task.

Essentially: how best can I run this all in one program, and in what language(s) ought I write it?

Apologies if I am not too clear. It's an idea popped into my head just earlier today. Thanks for any advice you can think of! :-)

Is This A Good Question/Topic? 0
  • +

Replies To: Simplest way to utilize XML?

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3485
  • View blog
  • Posts: 10,742
  • Joined: 05-May 12

Re: Simplest way to utilize XML?

Posted 26 February 2013 - 08:12 AM

If you are writing code in Java, I recommend sticking with JSON. Why complicate matters with XML, namespaces, DTDs, etc., especially if you should be processing things as objects entities, rather than as data rows?

You are on the right track of trying to keep everything within your program as much as possible. The lower your number of dependencies/moving parts, the better.

If you really want to read JSON, but store in XML, I'm quite sure that there are several well received XML libraries available to you in Java. For simple schemas, you could handcraft the code to write out the XML, and K.I.S.S., but you could probably make better use of your time by using a library. Remember that you'll have to handle escaping of characters like '<' and '&' within the incoming data than needs to get written out to the XML. A good library will take care of the escaping for you.
Was This Post Helpful? 0
  • +
  • -

#3 nullcoding  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 99
  • Joined: 08-July 12

Re: Simplest way to utilize XML?

Posted 26 February 2013 - 12:10 PM

Okay, thank you!

I will simply have to learn more about JSON, then. It's not that bad as is - I simply compiled the org.json package from, well, json.org...just gotta figure out a working method of obtaining the specific string (just an integer) that we need and then we're off.

I certainly have no qualms about foregoing XML altogether. I know a fair bit about it through using BOINC, as any and all end-user customisation or tweaking is done via the editing or creation of XML files, which are then read in Perl and the rest is a mystery to me.

The site from which we are pulling data is written almost entirely in Javascript. In fact, I think it IS entirely Javascript, which would explain the long load times, and also why we want to keep our own centralized database to reduce querying them all the time.

JSON it is, then! Thank you for the tips, as always.

I promise this program has nothing at all to do with prime numbers. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1