json:transform-to-json 有额外的 _value 元素

json:transform-to-json has extra _value element

我正在从数据库中提取文档,选择文档的一部分,然后使用 json:transform-to-[=26=运行将该部分转换为 json ],使用空 json:config("custom") 进行配置。我选择的 xml 部分没有任何属性,只有元素,但是在 t运行sformation 中,某些东西触发了元素同时具有值​​和属性的情况,并且正在添加一个_value 元素到包含换行符的 json。

这是我运行的一个测试程序,我从数据库中提取内容,并返回内容,内容的t运行sform,然后是t运行我刚刚从第一部分的控制台复制的硬编码内容的形式。我的期望是 t运行sformations 是相同的,但它们不是。

import module namespace json="http://marklogic.com/xdmp/json"
     at "/MarkLogic/json/json.xqy";

declare namespace pdbm = "http://schemas.abbvienet.com/people-db/model";

let $person := fn:collection()[1]//pdbm:person/pdbm:account

let $node :=
  <account xmlns:pdbe="http://schemas.abbvienet.com/people-db/envelope" xmlns="http://schemas.abbvienet.com/people-db/model">
    <domain>ABBVIENET</domain>
    <username>KOPECOX</username>
    <status>ENABLED</status>
  </account>

return ($person, json:transform-to-json($person, json:config("custom")), json:transform-to-json($node, json:config("custom")))

从数据库中选择的内容,在本例中为 $person t运行形式为:

{
  "account": {
    "domain": "ABBVIENET", 
    "username": "KOPECOX", 
    "status": "ENABLED", 
    "_value": "\n   "
  }
}

而与内容完全相同的$节点运行形成:

{
  "account": {
    "domain": "ABBVIENET", 
    "username": "KOPECOX", 
    "status": "ENABLED"
  }
}

自定义 json:config 实际上是一个 map:map,您可以向其中添加额外的标志,例如空格忽略。这似乎有帮助:

xquery version "1.0-ml";

import module namespace json="http://marklogic.com/xdmp/json"
     at "/MarkLogic/json/json.xqy";

let $node :=
  <account xmlns:pdbe="http://schemas.abbvienet.com/people-db/envelope" xmlns="http://schemas.abbvienet.com/people-db/model">
    <domain>ABBVIENET</domain>
    <username>KOPECOX</username>
    <status>ENABLED</status>
    { "&#10;" }
  </account>

let $config := json:config("custom")
let $_ := map:put($config, "whitespace", "ignore")
return json:transform-to-json($node, $config)

另请参阅 json:config 的文档:http://docs.marklogic.com/json:config

HTH!

如果您的 XML 有您想要保留的文本,您可以通过设置 "text-value" 键来更改默认的 json 字段名称。

  • text_value The JSON member name to use for text when an element contains both attributes and text.

http://docs.marklogic.com/json:config