我有 xml 文档,例如 -
<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>
我在 MarkLogic 中使用 JavaScript,并希望运行 element value query在 c:id
上。像这样的 -
cts.elementValueQuery(xs.QName("c:id"), "http://example.com/xyz/no-data")
但是为此我需要声明命名空间c
。如果是 xQuery,我们可以做这样的事情 -
declare namespace c="http://example.com/ns/core";
但我不知道如何在 JavaScript 中执行此操作。
最佳答案
您可以使用 fn.QName()而不是 xs.QName()。在下面的示例中,我将 nsC
(namespace-C) 声明为类似于声明的命名空间前缀。
const nsC = "http://example.com/ns/core";
cts.elementValueQuery(
fn.QName(nsC, "id"),
"http://example.com/xyz/no-data"
)
关于javascript - 如何在 JavaScript + Marklogic 中声明 xml 命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40127782/