Mongo - JS - How to convert a BSON/JSON object to XML

While using JS scripting with the mongo-shell API, how do I convert a JSON/BSON object into a XML string.

I would probably write the XML string to a file.

Answers


I grabbed the json2xml.js from here:

http://goessner.net/download/prj/jsonxml/json2xml.js

Then I saved it to the same folder as my mongo shell binary for convenience (so I didn't have to specify the full path. Here are the results:

> load("json2xml.js")
> db.bar.insert({"_id" : 123, foo : 1, x : "example"})
> db.bar.findOne()
{ "_id" : 123, "foo" : 1, "x" : "example" }
> json2xml(db.bar.findOne())
<_id>123</_id><foo>1</foo><x>example</x>

Now, you may need to extend this to deal with non-JSON types in MongoDB (see the BSON Specification page for details), but the basics are there.


Need Your Help

AVFoundation - Detect face and crop face area?

ios ipad crop face-detection

As title says i want to detect face and then to crop just the face area. This is what I have so far:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.