3

Working with XML in C++ seems a bit of a pain and I'm looking at a way to output JSON.

I've stumbled on two different approaches:

A) XSLT transformations: http://controlfreak.net/xml-to-json-in-xslt-a-toolkit/

B) Dedicated library such as this: https://github.com/Cheedoong/xml2json

I'm new to programming so pursuing an avenue is a very time consuming process. If possible id like to get some feedback on what might be a more recommended approach before I start.

I'm pulling in about 5000 xml entities and outputting json with curl to another server

Any help or advice would be appreciated.

closed as too broad by GlenH7, user22815, Ixrec, user40980, durron597 May 20 '15 at 2:19

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    Working with JSON in C++ also seems a bit of a pain, I would use javascript to work with JSON. You can use nodejs to run the code on a console. And if you are new to programming, javascript is a cool language to learn. What is your final goal? that's an important part of the question. – cauchy Apr 16 '15 at 15:04
  • 2
    This isn't a task for C++. This is a task for Python or Ruby or really any language but C++. – Sebastian Redl Apr 16 '15 at 15:05
  • @jbcolmenares My final goal is to take some xml nodes spat out from C++ (which does some fairly hefty computation) and get it into Elasticsearch as quickly and efficiently as possible. – Jimmy Apr 16 '15 at 15:06
  • 1
    Use the library - that's why libraries are for, and that one comes with source so you can tweak it to your exact needs if necessary. But the ultimate approach is to modify the sending application to spit out JSON instead. – gbjbaanb Apr 16 '15 at 15:08
  • 2
    Then you need to update the question a little: can you write a standalone app in any language or is it part of an existing C++ program? Is performance an issue? what languages do you (and colleagues) know as future maintenance is important. – gbjbaanb Apr 16 '15 at 15:19
6

From the comments... if everything else you have is C++ then the best answer is to write it in C++, building a mish-mash of different bits of programming languages is a right PitA to maintain and support.

So, if you have C++ and need to resolve XML to JSON, it seems obvious to use the xml2json library that you linked to. It comes with sources so you can modify it to suit any needs that it doesn't cater for, and should be the simplest answer to drop it into an existing component. You already have curl so this removes the need to come up with a different networking solution too.

  • I appreciate the answer. The XSLT solution also allows me to use C++, so I see it as on-par with xml2json, so is that not worth considering? – Jimmy Apr 16 '15 at 17:09
  • 1
    yes it is.. but you asked "which one do I choose". If you've already chosen xslt... get on with it! :) – gbjbaanb Apr 17 '15 at 7:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.