[JAVA-992] Insert easily into MongoDB - convert to DBObject Created: 07/Oct/13  Updated: 04/Dec/13  Resolved: 04/Dec/13

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Matt Kalan Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

It has come up many times to be able to take an XML message and insert into MongoDB as a proper BSON document (not an XML string).

Many people pose it as converting XML to JSON but of course one inserts into MongoDB through the MongoDB drivers so one doesn't actually convert to JSON and there are not standard public libraries for MongoDB like JSON.

It would be useful to have a method to convert an XML document (or have a constructor) to a DBObject, mapping attributes, elements, and multiple elements appropriately or with options to decide from a few reasonable ways of mapping.

I have heard this mostly from enterprises who mostly use Java so adding to this project but could be true of all the MongoDB drivers.



 Comments   
Comment by Jeffrey Yemin [ 08/Oct/13 ]

Though I did find http://www.bramstein.com/projects/xsltjson/, which tries its best.

Comment by Jeffrey Yemin [ 07/Oct/13 ]

Matt, there is no canonical mapping between XML and either JSON or BSON, and there are a number of problems with creating one (this list is not exhaustive):

  1. Without a schema, XML has no notion of data types. Every value is a string, so there is no way to reliably distinguish strings from int32 from int64 from boolean.
  2. XML has no built-in support for lists. One would have to derive it from repeated element names.
  3. XML has both attributes and elements, and they can have the same names.

Anything that we do, the customer would have to supply the mapping rules. There is nothing generic we can do that will reliably give accurate results.

Generated at Thu Feb 08 08:53:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.