finoutlook
finoutlook

Reputation: 2533

Should I parse XML and JSON separately or convert one to the other first?

I am collecting data from various web services, some return XML, some JSON. I've looked into JSON.Net as a parser for JSON, and it looks like it works well to extract the items I need, specifically using Linq.

Question is, should I go ahead and use JSON.Net's conversion methods, and just turn all the XML I receive into JSON before processing, meaning I only need to write parsing methods for JSON.

Can anyone think of an advantage of having separate XML parsing code (quering it with Linq probably). Are there disadvantages to using JSON if the data structures start to get complex?

Upvotes: 1

Views: 306

Answers (2)

Dustin Kingen
Dustin Kingen

Reputation: 21285

The only real difference I can see for using XML would be validating one's parse to a schema, although I have no idea as to JSON.NET's support for JSON Schema (currently an IETF draft).

Upvotes: 1

Ken Brittain
Ken Brittain

Reputation: 2265

Both formats can represent object graphs effectively so I don't think data structure complexity is a problem.

The only disadvantage of JSON that I have found is that XML is navigable. You can walk through the structure of an XML serialized object graph without actually creating the corresponding object graph. With JSON, unless I have missed something, you will need to create the object graph to navigate the structure.

I am not 100% sure but it would seem that Linq would acutally require the graph to be created in memory anyway. If that is true then the disadvantage disappears as a factor.

Upvotes: 1

Related Questions