动态xml到mongoDB中 [英] Dynamic xml into mongoDB

查看:557
本文介绍了动态xml到mongoDB中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发应用程序(Java),可以找到解决我的问题的最佳方法. 我需要将数据存储在mongoDB中(在bson格式支持时具有实际的数据类型),将数据存储在xml文件中,以及他的模式(两者都是在运行时动态创建的,所以我不知道其中是什么).

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).

更具体地说,我没有关于字段,数据名称的任何信息. 用户可以动态创建新的对象"(应用程序中没有Java类). 当用户创建一个新对象时,我会收到一个描述该对象的xml模式. 因此,当用户尝试添加这种类型的对象时(新实体的数据采用xml格式),我使用xml模式对其进行了验证,现在我需要将该对象存储在mogoDB中. 因此,我需要能够将bson(或带有mongo Java驱动程序的基本Java对象)中的xml转换为查询后的xml.

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.

示例:

如果用户要管理人员,则将定义人员架构:

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

<People>
   <Name>...</Name>
   <Lastname>...</Lastname>
   <Age>...</age>
   ...
</People>

在这里,我得到了xsd(具有所有信息的有效xsd格式).然后,当用户添加人员时,我将得到如下数据:

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:

<People>
   <Name>John</Name>
   <Lastname>Smith</Lastname>
   <Age>32</Age>
   ...
</People>

所以我想知道最好的方法是像jackson:xml-> Pojo-> bson,还是XSLT xml-> json/bson(对数据类型进行编码).或者简单地通过手动读取xml文件和基本的Java对象.

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?

推荐答案

最好的方法似乎是XML<-> JSON 请参阅:在Java中将XML转换为JSON的最快方法

Best approach would seem to go XML <-> JSON See: Quickest way to convert XML to JSON in Java

然后您可以使用com.mongodb.util.JSON解析和序列化来进行JSON<-> BSON.

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

这篇关于动态xml到mongoDB中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆