samedi 25 avril 2015

marklogic save xml document with node-client-api?


I can't seem to save xml document into the marklogic with it's node-client-api. I had used the following code to try to save a dummy xml document

var marklogic = require('marklogic');
var my = require('../db/env.js');
var db = marklogic.createDatabaseClient(my.connInfo);

console.log("Write a single dummy xml document");

db.documents.write(
{
        uri: '/collegiate/testxml.xml',
        contentType: 'application/xml',
        content: '<entry-list><entry id="horror"></entry></entry-list>'
})

Then I used the following code to retrieve it:

var marklogic = require('marklogic');
var my = require('../db/env.js');
var db = marklogic.createDatabaseClient(my.connInfo);

console.log("Read a single xml document");

db.documents.read('/collegiate/testxml.xml')
.result().then(function(document) {
    //console.log('\nURI: ' + document.uri);
    for (var key in document) {
        console.log("key: " + key + " value: " + document.key);
    }
}).catch(function(error) {
    console.log(error);
});

What I get from the output is:

Read a single xml document
key: 0 value: undefined

So how to save a xml document correctly?


Aucun commentaire:

Enregistrer un commentaire