Ankit Bhardwaj
Ankit Bhardwaj

Reputation: 774

How to declare xml namespace in JavaScript + Marklogic

I have xml documents like -

<domain xmlns:c="http://example.com/ns/core" xmlns="http://example.com/ns/core">
  <c:id>http://example.com/xyz/no-data</c:id>
</domain>

I am using JavaScript in MarkLogic, and want to run an element value query on c:id. Something like this -

cts.elementValueQuery(xs.QName("c:id"), "http://example.com/xyz/no-data")

But for this I need to declare the namespace c. Has it been xQuery we could have done something like this -

declare namespace c="http://example.com/ns/core";

But I am not able to get how to do this in JavaScript.

Upvotes: 3

Views: 384

Answers (1)

Dave Cassel
Dave Cassel

Reputation: 8422

You can use fn.QName() instead of xs.QName(). In the example below, I've declared nsC (namespace-C) as something analogous to a declared namespace prefix.

const nsC = "http://example.com/ns/core";
cts.elementValueQuery(
  fn.QName(nsC, "id"), 
  "http://example.com/xyz/no-data"
)

Upvotes: 5

Related Questions