【问题标题】:Retrieve a multipart/form-data file as XML nodes检索作为 XML 节点的 multipart/form-data 文件
【发布时间】:2015-11-26 20:06:28
【问题描述】:

我的表格有问题,我可以缩小到 下列的。它是一个多部分/表单数据类型的 POST,发送一个文件 部分:

------------------------------ed0cb8f98262
Content-Disposition: form-data; name="file"; filename="example.xml"
Content-Type: text/xml

<hello>World!</hello>

------------------------------ed0cb8f98262--

当我使用xdmp:get-request-field('file') 获取 te 值时,它是 作为包含一个文本节点的文档节点返回。如果我改变 text/plainapplication/octet-stream,值为二进制 节点。

我希望文档节点包含元素 hello。这 以下查询重现了问题(访问和输出一些 键值,仔细检查我的环境):

xquery version "1.0-ml";

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

declare namespace xdmp = "http://marklogic.com/xdmp";
declare namespace mt   = "http://marklogic.com/xdmp/mimetypes";

declare function local:type-from-filename($name as xs:string) as xs:string*
{
   let $ext   := fn:tokenize($name, '\.')[fn:last()]
   let $types := admin:mimetypes-get(admin:get-configuration())
   return
      $types[mt:extensions/data() = $ext]/mt:name
};

<fields version="{ xdmp:version() }">
{
   for $name     in xdmp:get-request-field-names()
   let $value    := xdmp:get-request-field($name)
   let $filename := xdmp:get-request-field-filename($name)
   return
      <field>
         <name>{ $name }</name>
         <is-text>{ $value/node() instance of text() }</is-text>
         <is-binary>{ $value/node() instance of binary() }</is-binary>
         <filename type="{ local:type-from-filename($filename) }">{ $filename }</filename>
         <content-type>{ xdmp:get-request-field-content-type($name) }</content-type>
         {
            if ( $value instance of binary() ) then
               <value>...binary...</value>
            else
               <value>{ $value }</value>
         }
      </field>
}
</fields>

当使用以下 CURL 命令调用时(只需将上面的查询 在 HTTP 应用服务器上,并调整用户、密码和端点 下面):

curl -u user:pwd --digest \
    -F "file=@.../example.xml;type=text/xml" \
    http://localhost:8010/test/tools/fields

它返回以下内容:

<fields version="8.0-4">
   <field>
      <name>file</name>
      <is-text>true</is-text>
      <is-binary>false</is-binary>
      <filename type="application/xml">example.xml</filename>
      <content-type>text/xml</content-type>
      <value>&lt;hello&gt;World!&lt;/hello&gt; </value>
   </field>
</fields>

当使用以下 CURL 命令调用时(注意不同的 类型=):

curl -u user:pwd --digest \
    -F "file=@.../example.xml;type=application/octet-stream" \
    http://localhost:8010/test/tools/fields

它返回以下内容:

<fields version="8.0-4">
   <field>
      <name>file</name>
      <is-text>false</is-text>
      <is-binary>false</is-binary>
      <filename type="application/xml">example.xml</filename>
      <content-type>application/octet-stream</content-type>
      <value>...binary...</value>
   </field>
</fields>

我错过了什么吗?我不应该得到一个 XML 文档节点吗?

问题也发布在 MarkLogic dev mailing list 上。

【问题讨论】:

    标签: marklogic


    【解决方案1】:

    在 XML 的文本表示上使用 xdmp:unquote() 将其转换为文档节点。

    【讨论】:

    • 嗯,当然,但是,咳咳,你知道,这听起来对我来说是个缺陷(甚至是回归?)我能保证我总是以文本形式接收它吗?还是二进制?还是……?
    • 不确定。;为此,我一直使用 xdmp:unquote。
    • 嗯.. 函数签名说它返回 item()*。这没有任何迹象表明它会为您解析任何字段的内容。唯一提到的是关于二进制。 JSON、XML——我们总是必须自己处理这些。如果您可以证明它曾经以另一种方式工作,那将是一个回归问题或错误。只是不按直觉预期工作并不一定表明存在错误或回归问题。是否有一个版本的 ML 让您注意到它的工作方式有所不同?
    猜你喜欢
    • 1970-01-01
    • 2021-08-30
    • 2018-12-28
    • 2021-06-23
    • 1970-01-01
    • 2021-08-10
    • 1970-01-01
    • 2018-09-20
    • 2023-04-03
    相关资源
    最近更新 更多