javascript - marklogic save xml document with node-client-api? -


i can't seem save xml document marklogic it's node-client-api. had used following code try save dummy xml document

var marklogic = require('marklogic');  var = require('../db/env.js');  var db = marklogic.createdatabaseclient(my.conninfo);    console.log("write single dummy xml document");    db.documents.write(  {  	uri: '/collegiate/testxml.xml',  	contenttype: 'application/xml',  	content: '<entry-list><entry id="horror"></entry></entry-list>'  })

then used following code retrieve it:

var marklogic = require('marklogic');  var = require('../db/env.js');  var db = marklogic.createdatabaseclient(my.conninfo);    console.log("read single xml document");    db.documents.read('/collegiate/testxml.xml')  .result().then(function(document) {      //console.log('\nuri: ' + document.uri);      (var key in document) {      	console.log("key: " + key + " value: " + document.key);      }  }).catch(function(error) {      console.log(error);  });

what output is:

read single xml document key: 0 value: undefined 

so how save xml document correctly?

the issue in read code.

because client can read multiple documents, read() request returns array of documents.

so, try like:

function(documents) {   (var i=0; < documents.length; i++) {     console.log(documents[i].content);   } } 

the repository has examples, though focus on json documents:

https://github.com/marklogic/node-client-api/blob/master/examples/read-documents.js#l27

hoping helps


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -