首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >以XML节点的形式检索多部分/表单数据文件

以XML节点的形式检索多部分/表单数据文件
EN

Stack Overflow用户
提问于 2015-11-27 04:06:28
回答 1查看 698关注 0票数 0

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

代码语言:javascript
复制
------------------------------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/plain更改为application/octet-stream,则该值是一个二进制节点。

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

代码语言:javascript
复制
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应用服务器上,并调整下面的用户、密码和端点):

代码语言:javascript
复制
curl -u user:pwd --digest \
    -F "file=@.../example.xml;type=text/xml" \
    http://localhost:8010/test/tools/fields

它返回以下内容:

代码语言:javascript
复制
<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命令调用时(请注意不同的type=):

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

它返回以下内容:

代码语言:javascript
复制
<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上。

EN

回答 1

Stack Overflow用户

发布于 2015-11-27 20:49:02

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33946268

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档