java mongodb xml,将动态XML导入mongoDB

I'am currently working on an application (Java), and can figured out the best way to solve my issue.

I need to store data in mongoDB (with the actual data type when supported by bson format), I get the data in an xml file, and his schema (both are created dynamically at runtime, so I have no idea what's in it).

To be more specific, I didn't have any information on the fields, names of the data.

A user can create new "object" (for which there is no java class in the application) dynamically.

When a user create a new object, I receive a xml schema which describe the object.

So when a user try to add an object of this type (data are in a xml format for the new entity), I validate it with the xml schema and now I need to store the object in mogoDB.

So I need to be able to transform my xml in bson (or basic java object with mongo java driver) and back into xml after a query.

Example:

If a user want to manage people, he will define the people schema:

...

...

...

...

Here I got the xsd (a valid xsd format with all informations). Then when a user add a People I get the data like that:

John

Smith

32

...

So i wonder if the best approach will be something like jackson: xml -> Pojo -> bson, or with XSLT xml -> json/bson (with encoding for data types). Or simply by reading the xml file and my basic java objects manually.

Did anyone have some advice on how to implements one of those solutions or better solutions?

解决方案

Best approach would seem to go XML JSON

See: Quickest way to convert XML to JSON in Java

Then you can go JSON BSON using com.mongodb.util.JSON parse and serialize.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值