1

I'm in a Hackathon and we have to use IBM Bluemix technologies. We are all new to NodeJs and IBM Bluemix.

We need to upload this XML (there are also TTL, RDF and N3 formats) in the way to create a db and upload everything into it.

Do you have any suggestion on how to do this?

4

3 回答 3

2

Personally, I'd :

  1. Read in the XML file
  2. Convert the XML model into a JSON object
  3. Then use the nano npm library to insert the data into Cloudant
于 2015-03-25T21:12:09.033 回答
1

The following example and code assume you are using Express 3. Express 4 is a little different with body parsing...

  1. Post the file to express.
  2. Read in the uploaded file
  3. Convert the XML to JSON.
  4. Store the JSON in your DB.

    app.post("/upload", function (request, response) {
        async.waterfall(
            [
                function (next) {
                    //where leads is the name of the field from your html page
                    fs.readFile(request.files.leads.path, next);
                },
                function (xml, next) {
                    var json = parser.toJson(xml);
                    db.insert(json, next)
                },
            ], function (error) {
                if (error) {
                    console.log(error);
                    response.send(error);
                    return;
                }
                response.redirect("/");
            }
        );
    });
    
于 2015-03-31T12:39:00.567 回答
0

Try damn-simple-xml to convert to a JavaScript object. It's easy to use and there is a good example of a simple case here.

于 2015-03-30T17:20:10.630 回答