Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a tool out there that can quickly and simply generate a DataContract from either XML or JSON? Doing it manually can be a real pain.

share|improve this question

closed as off topic by Thomas Owens Oct 24 '12 at 14:12

Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

See:… – NoChance Dec 26 '11 at 17:46
up vote 2 down vote accepted

To have a generator you need well defined structure. Both JSON and XML are just a way to describe data of any structure. You can probably write the generator to create class for the given XML or JSON snippet but it doesn't mean that the next snippet generated by the same source will have the same structure. For example your initial snippet can miss some optional data structures which will be included in the next snippet. Because of that generic generator doesn't make too much sense.

.NET offers tool to generate class from XML but the XML must be described by XSD - it clearly communicates valid structure of exchanged XML. The tool is called XSD.exe. In the same way you can create DataContracts from XSD by svcutil.exe with /dconly.

share|improve this answer
XSD.EXE can also make an XSD from an XML file by inferring the schema. As to the objection that your next snippet might not have the same structure, I would say that it very often does. In any case, the amount of effort required to fine-tune an XSD made in this way is probably much less than writing it from scratch. – Robert Harvey May 9 '11 at 19:01

While you mentioned needing to do this from XML/JSON .. here is a handy tool that will let you generate them from classes/entities, if you have them: DTO Generator.

share|improve this answer
Why? What's good about it? How did it help you? Providing a link is useful, but not as valuable as your experience that brought you to recommend it. Please expand your answer. – Walter Oct 24 '12 at 14:08
Way to be snarky and seriously daft. First, why what? Secondly, did you pass reading comprehension in elementary school? Obviously, it helped me generate Data Contracts / DTOs from entities, as my post stated. I'm sure you're familiar with the KISS principle. My post already answered your questions; there is nothing to expand. Had I literally posted just a link, you might have something. Since I didn't .. Thanks for the pointless downvote. – JoeBrockhaus Oct 26 '12 at 20:25
For others in similar situations as I .. where this was a top 3 result in google for my query (yet the answers were completely irrelevant and unhelpful) .. this would certainly be seen as helpful. Your trash is anothers' treasure. – JoeBrockhaus Oct 26 '12 at 20:26
Your answer was tagged by the SE engine as a "Low Quality" answer by a new user. Any 10K point user would have seen it and taken the same action. Snarky or not, your answer provided little value over that which can be found in a google search. As for pointless downvoting, you'll have to direct your ire towards the person who actually cast that vote. – Walter Oct 26 '12 at 22:41
I assumed the downvote was yours; you were the only comment. AFAIK, there is no way to know who did it. 2nd, do you mean 'downvote' in 'any 10k user would take same action'? If it was the intent that auto-flagged-low-qual answers be downvoted, why wouldn't it just do that? AFAICT, that's not the intent. I got here after googling as you suggest, because this was a top 3 result for whatever reason, while the DTO generator I posted wasn't in a variety of searches. ERGO, why I posted the answer: it would have been freaking helpful TO ME / similar others. your horse may be high, but it sure is SLOW – JoeBrockhaus Apr 29 '13 at 20:52

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