1

I am working learning the Javascript API for MarkLogic.

I do a query:

cts.search(
  cts.andQuery(
    [cts.wordQuery("abc"), cts.collectionQuery(["Strings"])]
  )
);

And get XML. I know how to convert this XML to JSON in XQuery, but how do I do it in Node? I can't seem to find it in the documentation.

1 Answer 1

3

This functionality is available in external modules. I've used xml2js and never had a problem, so I can recommend that.

Once you've installed the module (npm install --save xml2js), you can do something like this:

var parseString = require('xml2js').parseString;
var xml = "<root>Hello xml2js!</root>"
parseString(xml, function (err, result) {
    console.dir(JSON.stringify(result));
});
Sign up to request clarification or add additional context in comments.

1 Comment

Oh I was looking for a MarkLogic library, but I just had the revelation that now that I'm working on using the node API instead of XQuery, I don't need to rely on their libraries anymore. Now I can use the full power of npm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.